package com.scalar.chiptrack.sales.actions.quote;

import com.scalar.ScalarException;
import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.tags.attachFileTag;
import com.scalar.chiptrack.tags.InternalCommentsTag;
import com.scalar.chiptrack.operations.packingslip.PackingSlipComparator;
import com.scalar.chiptrack.operations.vendor.dao.VendorDAO;
import com.scalar.chiptrack.alarms.Alarm;
import com.scalar.chiptrack.alarms.AlarmUser;
import com.scalar.chiptrack.commons.Constants;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.commons.Address;
import com.scalar.chiptrack.commons.Labels;
import com.scalar.chiptrack.commons.dao.AttachFileDAO;
import com.scalar.chiptrack.commons.dao.InternalCommentsDAO;
import com.scalar.chiptrack.commons.actions.InternalCommentsAction;
import com.scalar.chiptrack.db.DBTransaction;
import com.scalar.chiptrack.sales.*;
import com.scalar.chiptrack.sales.LineItem;
import com.scalar.chiptrack.sales.Quotation;
import com.scalar.chiptrack.sales.SalesOrder;
import com.scalar.chiptrack.sales.actions.SalesOrderAction;
import com.scalar.chiptrack.sales.dao.*;
import com.scalar.chiptrack.sales.dao.quote.QuotationDAO;
import com.scalar.chiptrack.sales.forms.quote.QuotationForm;
import com.scalar.chiptrack.sales.forms.quote.ApproverQuotationForm;
import com.scalar.chiptrack.users.User;
import com.scalar.chiptrack.users.dao.UserDAO;
import com.scalar.chiptrack.utils.ConfigManager;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.chiptrack.utils.FileUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.MessageResources;
import org.apache.struts.upload.FormFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.io.File;


/**
 * Implementation of <strong>Action</strong> that gives customers list,
 * search with customer name, create Quotation
 *
 * @author Basha
 * @version $Revision: 1.35 $ $Date: 2004/02/04
 */

public final class QuotationAction extends ChipTrackAction
{

    private static final String ACTION_NAME = "/newQuotation.do";
    int isSample = 1;

    public ActionForward execute ( ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response )
            throws Exception
    {

        QuotationForm subform = ( QuotationForm ) form;
        HttpSession session = request.getSession ();

        User user = ( User ) session.getAttribute ( SessionKeys.USER_KEY );
        String action = request.getParameter ( "action" );
        String selectedCustomer = null;
        /*if ( user == null )
        {
            session.setAttribute ( SessionKeys.SOURCE_PAGE_KEY, ACTION_NAME + "?" + request.getQueryString () );
            return ( mapping.findForward ( "login" ) );
        }*/
        if ( user == null )
        {
            if( "printView".equals ( action ) )
            {
                request.setAttribute ( "closeWindowAfterSessionExp", "true" );
			    return ( mapping.findForward( "printView" ) );
            }
            else{
                session.setAttribute ( SessionKeys.SOURCE_PAGE_KEY, ACTION_NAME + "?" + request.getQueryString () );
                return ( mapping.findForward ( "login" ) );
            }
        }

        /* Commented by Prabhanjan, Sep 17, 2004
        // Great Plains Sales Integration Re-direction -----------------------------------------
        // Prabhanjan on Feb 24, 2004

        if ( Constants.FINANCE_INTEGRATION_TYPE_GREAT_PLAINS.equalsIgnoreCase ( ConfigManager.getFinanceIntegrationType () ) == true )
        {
            return new GPQuotationAction ().execute ( mapping, form, request, response );
        }
        // Great Plains Re-direction -----------------------------------------------------------
        */


        HashMap errors = new HashMap ();
        HashMap info = new HashMap ();

        selectedCustomer = request.getParameter ( "customerId" );
        Quotation quotationFromMap = null;
        HashMap  quotationMap = ( HashMap ) session.getAttribute( "quotationMap" );
        if ( quotationMap != null )
        {
            quotationFromMap = ( Quotation ) quotationMap.get( selectedCustomer );
            if( quotationFromMap == null )
            {
                if ( "NewQuotation".equalsIgnoreCase( action ) == false  && "printView".equalsIgnoreCase( action ) == false )
                {
                    errors.put( ERROR_QUOTATION_ALREADY_SAVED_FOR_SAME_CUSTOMER, null);
                    request.setAttribute ( SessionKeys.ERROR_MESSAGES, errors );
                    action = "NewQuotation";
                }
                else
                {
                    quotationMap.put( selectedCustomer, new Quotation() );
                }
            }
        }

        if ( "NewQuotation".equals ( action ) )
        {
            session.removeAttribute ( "QuotationForm" );
            Quotation quotation = QuotationDAO.getQuotationCustomerDetails ( selectedCustomer );
            if ( quotationMap == null )
            {
                quotationMap = new HashMap(5);
            }
            quotationMap.put ( selectedCustomer, quotation );
            session.setAttribute ( "quotationMap", quotationMap );
            PropertyUtils.copyProperties ( subform, quotation );

            subform.setQuotationNo ( QuotationDAO.getAutomatedQuoteNo () );

            ArrayList lineItems = getLineItems ( session );

            request.setAttribute ( "lineItems", lineItems );
            request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
            request.setAttribute ( "shippingMethods", subform.getShippingMethods () );
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );

            if ( subform.getShippingMethodName () != null )
            {
                subform.setShippingMethodName ( subform.getShippingMethodName ().trim () );
            }
            if ( subform.getShippingAccount () != null )
            {
                subform.setShippingAccount ( subform.getShippingAccount ().trim () );
            }

            request.setAttribute ( "Account", subform.getShippingMethodName () + "   #   " + subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingMethodName () + "   #   " + subform.getShippingAccount () );

            quotation.setMfgParts ( SalesOrderDAO.loadAllManfacturingPartNosOfCustomerWithOutobsolete ( Integer.parseInt ( selectedCustomer ), isSample ) );
            quotation.setMfgPartsWithComments ( SalesOrderDAO.loadAllManfacturingPartNumbersWithComments ( Integer.parseInt ( selectedCustomer ), isSample ) );
            quotation.setMfgPartsWithBaseOrderQty ( SalesOrderDAO.loadManufacturingPartNumbersWithBaseOrderQty ( null,  Integer.parseInt ( selectedCustomer ) ) );
            quotation.setMfgPartsWithCustomerPartNos ( NewSalesOrderDAO.loadManfacturingPartNumbersWithCustomerPartNumbers( Integer.parseInt ( selectedCustomer ), subform.getOdmId(), isSample ) ) ;
            quotation.setMfgPartsWithLabelNumbers ( NewSalesOrderDAO.loadManfacturingPartNumbersWithOdmLabelNumbers ( Integer.parseInt ( selectedCustomer ), subform.getOdmId(), isSample ) );

            session.setAttribute ( "salesTaxes", SalesDAO.loadSalesTaxList () );

            Address addressObject = CustomerDAO.getAddress ( quotation.getBillingAddressId () );
            ContactPerson contactPerson = new ContactPerson();
            contactPerson.setContactPerson( subform.getCustomerName() );
            contactPerson.setPhoneNumber(addressObject.getPhoneNumber());
            contactPerson.setCellNumber("");
            contactPerson.setFaxNumber(addressObject.getFaxNumber());
            contactPerson.setEmail(addressObject.getEmail());
            HashMap customerContactPersonMap = CustomerDAO.getContactPersonDetailsMap ( Integer.parseInt ( request.getParameter ( "customerId" ) ) );
            customerContactPersonMap.put(subform.getCustomerName(),contactPerson);
            quotation.setCustomerContactPersonMap( customerContactPersonMap );
            HashMap billingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getBillingAddressId() , quotation.getBillingAddressAsObject ());
            addressObject.setContactPerson( "" );
            addressObject.setCellNumber( "" );
            billingAddressMap.put("",addressObject.getAddressAsString());
            HashMap shippingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getShippingAddressId() , quotation.getShippingAddressAsObject ());
            Address shipAddress = CustomerDAO.getAddress ( quotation.getShippingAddressId () );
            shippingAddressMap.put  ( "",shipAddress.getAddressWithoutContactPersonAsString());
            quotation.setBillingAddressMap ( billingAddressMap );
            quotation.setShippingAddressMap ( shippingAddressMap );
            quotation.setSalesPersons ( CustomerDAO.loadAllSalesPersonsforCustomer( Integer.parseInt ( selectedCustomer ) ) ) ;
            quotation.setSalesReps ( CustomerDAO.loadAllSalesRepsforCustomer( Integer.parseInt ( selectedCustomer ) ) ) ;
            quotation.setOdmList ( CustomerRelationshipDAO.getAllOdmsForCustomer( selectedCustomer ) ) ;
            quotation.setEndCustomerList ( CustomerRelationshipDAO.getAllEndCustomersForCustomer( selectedCustomer ) ) ;
            session.setAttribute ( "allShippingTerms", quotation.getAllShippingTerms () );
            session.setAttribute ( "allDeliveryTerms", quotation.getAllDeliveryTerms() );
            session.setAttribute ( "shippingInstructions", NewSalesOrderDAO.loadShippingInstructions( null ) );
            session.setAttribute ( "freightInstructions", NewSalesOrderDAO.loadFreightInstructions( null ) );
            session.setAttribute ( "vendorDetails", VendorDAO.getVendorNamesByProcessByUserType( null, Constants.LOCATION_TYPE_FINISHED_GOODS, null ) );
            session.setAttribute ( "endCustomerList", quotation.getEndCustomerList());
            session.setAttribute ( "odmList", quotation.getOdmList());
            session.setAttribute ( "endCustomerList", quotation.getEndCustomerList());
            session.setAttribute ( "quotationTypesList", getQuotationTypesList() );
            session.setAttribute ( "qtyPerOptionsList", getQtyPerOptionsList());

            session.setAttribute ( "commitmentsList", getCommitmentsList());
            session.setAttribute ( "quantityiesList", getQuantityiesList());
            session.setAttribute ( "priceDiscountOptionsList", getPriceDiscountOptionsList());
            session.setAttribute ( "rebateGoalsList", getRebateGoalsList());
            session.setAttribute ( "competitorsList", QuotationDAO.getCompetitors(null));
            request.setAttribute ( "QuotationForm", subform );

            if (subform.getCustomerId()>0)
            {

                 ArrayList prevQuotationList= QuotationDAO.getPrevQuotationDetails(null, subform.getCustomerId());
                 ArrayList prevQuotationPriceList= QuotationDAO.getPrevQuotationPriceDetails(null, subform.getCustomerId());
                 request.setAttribute("prevQuotationsList", prevQuotationList);
                 request.setAttribute("prevQuotationPriceList", prevQuotationPriceList);
                 request.setAttribute( "prevCommitmentsDetails", QuotationDAO.getPrevCommitmentsDetails(null, subform.getCustomerId()));
            }
            saveToken ( request );
            if(ConfigManager.isLoadQuotationQuestionnaire())
            {
                return ( mapping.findForward ( "QuotationQuestionnaire" ) );
            }
            else
            {
                return ( mapping.findForward ( "Quotation" ) );
            }
        }
        else if ( "NewQuotationWithQuestion".equals(action))
        {
            Quotation quotation = QuotationDAO.getQuotationCustomerDetails ( selectedCustomer );
            QuotationDAO.getQuotationCustomerDetail( subform, selectedCustomer );
            ArrayList lineItems = getLineItems ( session );
            request.setAttribute ( "lineItems", lineItems );
            request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
            request.setAttribute ( "shippingMethods", subform.getShippingMethods () );
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );

            if ( subform.getShippingMethodName () != null )
            {
                subform.setShippingMethodName ( subform.getShippingMethodName ().trim () );
            }
            if ( subform.getShippingAccount () != null )
            {
                subform.setShippingAccount ( subform.getShippingAccount ().trim () );
            }

            request.setAttribute ( "Account", subform.getShippingMethodName () + "   #   " + subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingMethodName () + "   #   " + subform.getShippingAccount () );

            quotation.setMfgParts ( SalesOrderDAO.loadAllManfacturingPartNosOfCustomerWithOutobsolete ( Integer.parseInt ( selectedCustomer ), isSample ) );
            quotation.setMfgPartsWithComments ( SalesOrderDAO.loadAllManfacturingPartNumbersWithComments ( Integer.parseInt ( selectedCustomer ), isSample ) );
            quotation.setMfgPartsWithBaseOrderQty ( SalesOrderDAO.loadManufacturingPartNumbersWithBaseOrderQty ( null,  Integer.parseInt ( selectedCustomer ) ) );
            quotation.setMfgPartsWithCustomerPartNos ( NewSalesOrderDAO.loadManfacturingPartNumbersWithCustomerPartNumbers( Integer.parseInt ( selectedCustomer ), subform.getOdmId(), isSample ) ) ;
            quotation.setMfgPartsWithLabelNumbers ( NewSalesOrderDAO.loadManfacturingPartNumbersWithOdmLabelNumbers ( Integer.parseInt ( selectedCustomer ), subform.getOdmId(), isSample ) );

            session.setAttribute ( "salesTaxes", SalesDAO.loadSalesTaxList () );

            Address addressObject = CustomerDAO.getAddress ( quotation.getBillingAddressId () );
            ContactPerson contactPerson = new ContactPerson();
            contactPerson.setContactPerson( subform.getCustomerName() );
            contactPerson.setPhoneNumber(addressObject.getPhoneNumber());
            contactPerson.setCellNumber("");
            contactPerson.setFaxNumber(addressObject.getFaxNumber());
            contactPerson.setEmail(addressObject.getEmail());
            HashMap customerContactPersonMap = CustomerDAO.getContactPersonDetailsMap ( Integer.parseInt ( request.getParameter ( "customerId" ) ) );
            customerContactPersonMap.put(subform.getCustomerName(),contactPerson);
            quotation.setCustomerContactPersonMap( customerContactPersonMap );
            HashMap billingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getBillingAddressId() , quotation.getBillingAddressAsObject ());
            addressObject.setContactPerson( "" );
            addressObject.setCellNumber( "" );
            billingAddressMap.put("",addressObject.getAddressAsString());
            HashMap shippingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getShippingAddressId() , quotation.getShippingAddressAsObject ());
            Address shipAddress = CustomerDAO.getAddress ( quotation.getShippingAddressId () );
            shippingAddressMap.put  ( "",shipAddress.getAddressWithoutContactPersonAsString());
            quotation.setBillingAddressMap ( billingAddressMap );
            quotation.setShippingAddressMap ( shippingAddressMap );
            quotation.setSalesPersons ( CustomerDAO.loadAllSalesPersonsforCustomer( Integer.parseInt ( selectedCustomer ) ) ) ;
            quotation.setSalesReps ( CustomerDAO.loadAllSalesRepsforCustomer( Integer.parseInt ( selectedCustomer ) ) ) ;
            quotation.setOdmList ( CustomerRelationshipDAO.getAllOdmsForCustomer( selectedCustomer ) ) ;
            quotation.setEndCustomerList ( CustomerRelationshipDAO.getAllEndCustomersForCustomer( selectedCustomer ) ) ;
            session.setAttribute ( "allShippingTerms", quotation.getAllShippingTerms () );
            session.setAttribute ( "allDeliveryTerms", quotation.getAllDeliveryTerms() );
            session.setAttribute ( "shippingInstructions", NewSalesOrderDAO.loadShippingInstructions( null ) );
            session.setAttribute ( "freightInstructions", NewSalesOrderDAO.loadFreightInstructions( null ) );
            session.setAttribute ( "vendorDetails", VendorDAO.getVendorNamesByProcessByUserType( null, Constants.LOCATION_TYPE_FINISHED_GOODS, null ) );
            session.setAttribute ( "endCustomerList", quotation.getEndCustomerList());
            session.setAttribute ( "odmList", quotation.getOdmList());
            session.setAttribute ( "endCustomerList", quotation.getEndCustomerList());
            session.setAttribute ( "quotationTypesList", getQuotationTypesList() );
            session.setAttribute ( "qtyPerOptionsList", getQtyPerOptionsList());
            session.setAttribute ( "commitmentsList", getCommitmentsList());
            session.setAttribute ( "quantityiesList", getQuantityiesList());
            session.setAttribute ( "priceDiscountOptionsList", getPriceDiscountOptionsList());
            session.setAttribute ( "rebateGoalsList", getRebateGoalsList());
            session.setAttribute ( "competitorsList", QuotationDAO.getCompetitors(null));
            //session.setAttribute ( "quotationQuestionnairyList", subform.getQuotationQuestionnairyList());
            session.setAttribute("questionnairefile"+ subform.getQuotationNo(), subform.getContractPriceFilePath());
            request.setAttribute ( "QuotationForm", subform );
            quotationFromMap.setShippingMethods( subform.getShippingMethods() );
            saveToken ( request );
            return ( mapping.findForward ( "Quotation" ) );
        }
        else if ( "UpdateQuotation".equals ( action ) )
        {
            addNewSalesTaxState ( request, session, errors, subform );

            request.setAttribute ( "QuotationForm", subform );

            if ( ( subform.getShippingAddressId () == -1 ) && ( session.getAttribute ( "newShippingAddressId" ) != null ) ) {
                subform.setShippingAddressId ( Integer.parseInt ( ( String ) session.getAttribute ( "newShippingAddressId" ) ) );
                Address address = CustomerDAO.getAddress( subform.getShippingAddressId() );
                loadShippingAddress( address, quotationFromMap.getShippingAddresses(), quotationFromMap );
            }
            subform.setShippingMethod ( subform.getShippingAccount () );

            ArrayList lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample );
            request.setAttribute ( "lineItems", lineItems );
            request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
            session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );

            subform.setTotalQty ( Integer.parseInt ( ( String ) request.getAttribute ( "totalQty" ) ) );
            subform.setSalesTaxAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "salesTax" ) ) );
            subform.setSubTotalAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "subTotal" ) ) );
            subform.setOrderTotalAsDouble ( subform.getSubTotalAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSalesTaxAsDouble () );

            session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );

            request.setAttribute ( "Account", subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingAccount () );

            if ( subform.getOdmId() > 0 )
            {
                quotationFromMap.setSalesPersons( NewCustomerDAO.loadAllSalesPersonsforCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ) ) ;
            }
            else
            {
                quotationFromMap.setSalesPersons( CustomerDAO.loadAllSalesPersonsforCustomer( subform.getCustomerId ())) ;
            }
            quotationFromMap.setShippingMethods( CustomerDAO.loadShippingMethodsForCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ));
            errors = ( HashMap ) request.getAttribute ( "Errors" );

            if ( !errors.isEmpty () )
            {
                request.setAttribute ( SessionKeys.ERROR_MESSAGES, errors );
            }

            saveToken ( request );

            return ( mapping.findForward ( "Quotation" ) );
        }
        else if ( "SubmitQuotation".equals ( action ) )
        {
            if ( ( subform.getShippingAddressId () == -1 ) && ( session.getAttribute ( "newShippingAddressId" ) != null ) )
            {
                subform.setShippingAddressId ( Integer.parseInt ( ( String ) session.getAttribute ( "newShippingAddressId" ) ) );
                Address address = CustomerDAO.getAddress( subform.getShippingAddressId() );
                loadShippingAddress( address, quotationFromMap.getShippingAddresses(), quotationFromMap );
                session.removeAttribute ( "newShippingAddressId" );
            }

            addNewShippingMethod ( request, session, errors, info, subform, quotationFromMap );
            addNewSalesTaxState ( request, session, errors, subform );
            addNewShippingTerms ( request, session, errors, info, subform );
            addNewDeliveryTerms ( request, session, errors, info, subform );
            addNewShippingInstructions ( request, session, errors, info, subform );
            addNewFreightInstructions ( request, session, errors, info, subform );

            session.setAttribute ( "QuotationForm", subform );
            if ( subform.getOdmId() > 0 )
            {
                quotationFromMap.setSalesPersons( NewCustomerDAO.loadAllSalesPersonsforCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ) ) ;
            }
            else
            {
                quotationFromMap.setSalesPersons( CustomerDAO.loadAllSalesPersonsforCustomer( subform.getCustomerId ())) ;
            }

            ArrayList lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, true, isSample );
            session.setAttribute ( "lineItems", lineItems );
            session.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
            session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );
            request.setAttribute ( "Account", subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingAccount () );
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );

            subform.setTotalQty ( Integer.parseInt ( ( String ) request.getAttribute ( "totalQty" ) ) );
            subform.setSalesTaxAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "salesTax" ) ) );
            subform.setSubTotalAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "subTotal" ) ) );
            subform.setOrderTotalAsDouble ( subform.getSubTotalAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSalesTaxAsDouble () );


            session.setAttribute ( "totalQty", request.getAttribute ( "totalQty" ) );
            session.setAttribute ( "salesTax", request.getAttribute ( "salesTax" ) );
            session.setAttribute ( "subTotal", request.getAttribute ( "subTotal" ) );
            session.setAttribute ( "orderTotal", Double.toString ( subform.getSalesTaxAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSubTotalAsDouble () ) );
            session.setAttribute ( "tempShippingMethod", subform.getShippingMethod () );
            subform.setOdm( CustomerDAO.getCustomerName(null,subform.getOdmId()) );
            subform.setEndCustomer( CustomerDAO.getCustomerName( null, subform.getEndCustomerId() ) );
            request.setAttribute ( "QuotationForm", subform );
            errors = ( HashMap ) request.getAttribute ( "Errors" );
            if ( !errors.isEmpty () )
            {
                request.setAttribute ( SessionKeys.ERROR_MESSAGES, errors );
                return ( mapping.findForward ( "Quotation" ) );
            }

            info = ( HashMap ) request.getAttribute ( "Info" );
            if ( !info.isEmpty () )
            {
                request.setAttribute ( SessionKeys.INFO_MESSAGES, info );
            }

            saveToken ( request );

            return ( mapping.findForward ( "ConfirmQuotation" ) );
        }
        else if ( "printView".equals ( action ) )
        {
            ApproverQuotationForm approverQuotationForm = new ApproverQuotationForm ();
            Quotation quotation = new Quotation ();
            QuotationForm quotationForm = ( QuotationForm ) session.getAttribute ( "QuotationForm" );
            Customer customer = new Customer();

            customer.setCustomerId( quotationForm.getCustomerId() );
            CustomerDAO.getCustomerDetailsForAcknowledgement( null, customer );
            request.setAttribute ( "customer", customer );

            PropertyUtils.copyProperties ( quotation, quotationForm );
            QuotationDAO.loadClientAddress ( quotation );
            quotation.setShippingAddressAsObject( CustomerDAO.getAddressWithContactPersonDetails( quotation.getShippingAddressId(), quotation.getShippingContactPerson()) );
            quotation.setBillingAddressAsObject( CustomerDAO.getAddressWithContactPersonDetails( quotation.getBillingAddressId(), quotation.getBillingContactPerson(), quotation.getCustomerId() ) );
            //quotation.setVendorAddressAsObject( VendorDAO.getVendorNameAndAddress(quotation.getVendorId()));
            quotation.setShippingAccount ( ( String ) session.getAttribute ( "tempShippingMethod" ) );

            quotation.setTotalQty ( ( String ) session.getAttribute ( "totalQty" ) );
            quotation.setFinalSubTotal ( Double.parseDouble ( ( String ) session.getAttribute ( "subTotal" ) ) );
            quotation.setFinalSalesTax ( Double.parseDouble ( ( String ) session.getAttribute ( "salesTax" ) ) );
            quotation.setFinalOrderTotal ( Double.parseDouble ( ( String ) session.getAttribute ( "orderTotal" ) ) );

            approverQuotationForm.setQuotationId( quotationForm.getQuotationId() );
            approverQuotationForm.setQuotationNo( quotationForm.getQuotationNo() );

            String clientaddressId =  UserDAO.getClientAddressId();
            String addressId = null;
            String clientname = null;

            int finalAddressId = 0;
            if(clientaddressId != null)
            {
                StringTokenizer st = new StringTokenizer(clientaddressId,"@");
                try
                {
                    addressId = st.nextToken();
                    clientname = st.nextToken();
                }catch(NoSuchElementException e)
                {
                     clientname  = "";
                }
            }
            if(addressId  != null)
            {
                finalAddressId = Integer.parseInt(addressId);
            }
            Address clientAddress= UserDAO.loadClientAddressDetails( null , finalAddressId );

            quotation.setClientAddressAsObject(clientAddress);
            String clientAddress1 = SalesOrder.getClientAddressAsString(clientAddress);
            quotation.setClientAddress(clientAddress1);
            quotation.setClientName(clientname);

            approverQuotationForm.setQuotation( quotation );

            request.setAttribute ( "approverQuotationForm", approverQuotationForm );
            request.setAttribute ( "lineItems", session.getAttribute ( "lineItems" ) );

            ArrayList list = (ArrayList) request.getAttribute("lineItems");
            if ( list != null )
            {
                Collections.sort (list , new PackingSlipComparator () );
            }
            request.setAttribute ( "termsAndConditions", SalesDAO.loadTermsAndConditionsAsList () );

            request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals( list ) );
            return ( mapping.findForward ( "printView" ) );
        }
        else if ( "EditQuotation".equals ( action ) )
        {
            if ( !isTokenValid ( request ) )
            {
                errors.put ( ERROR_QUOTATION_ALREADY_SAVED, null );
            }

            resetToken ( request );

            if ( !errors.isEmpty () )
            {
                request.setAttribute ( SessionKeys.ERROR_MESSAGES, errors );
                saveToken ( request );
                return ( mapping.findForward ( "successQuotation" ) );
            }

            request.setAttribute ( "QuotationForm", session.getAttribute ( "QuotationForm" ) );

            subform.setShippingMethod ( subform.getShippingAccount () );
            String hdnShippingMethodName = request.getParameter ( "hdnShippingMethodName" );
            String hdnshippingAccount = request.getParameter ( "hdnshippingAccount" );

            request.setAttribute ( "Account", hdnshippingAccount );
            request.setAttribute ( "Method", hdnShippingMethodName );
            request.setAttribute ( "lineItems", request.getAttribute ( "lineItems" ) );
            session.setAttribute ( "maxLineItemNo", session.getAttribute ( "maxLineItemNo" ) );
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );
            quotationFromMap.setShippingMethods( CustomerDAO.loadShippingMethodsForCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ));
            saveToken ( request );

            return ( mapping.findForward ( "Quotation" ) );
        }

        else if ( "loadODMDetails".equals ( action ) )
        {
            String odmId = request.getParameter ( "odmId" );
            ArrayList lineItems = null;
            if ( ( subform.getShippingAddressId () == -1 ) && ( session.getAttribute ( "newShippingAddressId" ) != null ) ) {
                subform.setShippingAddressId ( Integer.parseInt ( ( String ) session.getAttribute ( "newShippingAddressId" ) ) );
                Address address = CustomerDAO.getAddress( subform.getShippingAddressId() );
                loadShippingAddress( address, quotationFromMap.getShippingAddresses(), quotationFromMap );
            }
            if ( odmId != null )
            {
                if ( "-1".equals ( odmId.trim () ) )
                {
                    Quotation quotation = QuotationDAO.getQuotationCustomerDetails ( Integer.toString ( subform.getCustomerId () ) );
                    subform.setContactPersons ( quotation.getContactPersons () );
                    subform.setContactPersonsForBillingAddress ( quotation.getContactPersonsForBillingAddress () );
                    subform.setContactPersonsForShippingAddress ( quotation.getContactPersonsForShippingAddress () );
                    subform.setShippingAddress ( quotation.getShippingAddressAsObject() != null ? quotation.getShippingAddressAsObject().getAddressAsString() : "" );
                    HashMap shippingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getShippingAddressId() , quotation.getShippingAddressAsObject ());
                    Address shipAddress = CustomerDAO.getAddress ( quotation.getShippingAddressId () );
                    shippingAddressMap.put("",shipAddress.getAddressWithoutContactPersonAsString() );
                    request.setAttribute ( "shippingAddressMap", shippingAddressMap );
                    subform.setShippingAddresses ( quotation.getShippingAddresses () );
                    quotationFromMap.setShippingAddresses( quotation.getShippingAddresses () );
                    subform.setOdm("");
                    subform.setShippingAddressId ( quotation.getShippingAddressId () );
                    subform.setShippingContactPerson ( quotation.getShippingContactPerson () );
                    quotationFromMap.setSalesPersons( CustomerDAO.loadAllSalesPersonsforCustomer( Integer.parseInt ( selectedCustomer ) ) ) ;
                    quotationFromMap.setMfgPartsWithCustomerPartNos( NewSalesOrderDAO.loadManfacturingPartNumbersWithCustomerPartNumbers( Integer.parseInt ( selectedCustomer ), subform.getOdmId(), isSample ) ) ;
                    quotationFromMap.setMfgPartsWithLabelNumbers( NewSalesOrderDAO.loadManfacturingPartNumbersWithOdmLabelNumbers ( Integer.parseInt ( selectedCustomer ), subform.getOdmId(), isSample ) );
                    quotationFromMap.setShippingMethods( CustomerDAO.loadSalesOrderShippingMethods ( subform.getCustomerId() ) );
                    subform.setShippingMethods( CustomerDAO.loadSalesOrderShippingMethods ( subform.getCustomerId() ) );
                }
                else
                {
                    Quotation odmQuotation = QuotationDAO.getQuotationCustomerDetails ( odmId );
                    Quotation quotation = QuotationDAO.getQuotationCustomerDetails ( Integer.toString ( subform.getCustomerId () ) );
                    Address customerShippingAddress = quotation.getShippingAddressAsObject();
                    subform.setOdm( CustomerDAO.getCustomerName( null, Integer.parseInt( odmId ) ) );
                    subform.setEndUserId( "" );
                    subform.setEndUser("");
                    subform.setContactPersonsForBillingAddress( quotation.getContactPersonsForBillingAddress () );
                    subform.setContactPersonsForShippingAddress( odmQuotation.getContactPersonsForShippingAddress() );
                    subform.setShippingAddress ( SalesOrder.getAddressAsString ( odmQuotation.getShippingAddressAsObject () ) );
                    subform.setShippingContactPerson( odmQuotation.getShippingContactPerson () );
                    subform.setShippingAddressId ( odmQuotation.getShippingAddressId ()  );
                    ArrayList shippingAddresses = odmQuotation.getShippingAddresses ();
                    subform.setContactPersons ( quotation.getContactPersons () );
                    HashMap shippingAddressMap = CustomerDAO.getAddressDetailsMap ( odmQuotation.getShippingAddressId() , odmQuotation.getShippingAddressAsObject ());
                    Address shipAddress = CustomerDAO.getAddress(odmQuotation.getShippingAddressId());
                    shipAddress.setContactPerson("");
                    shipAddress.setPhoneNumber("");
                    shipAddress.setCellNumber("");
                    shipAddress.setFaxNumber("");
                    shipAddress.setEmail("");
                    shippingAddressMap.put("",SalesOrder.getAddressAsString(shipAddress));
                    quotationFromMap.setShippingAddressMap( shippingAddressMap );
                    Address address = odmQuotation.getShippingAddressAsObject();
                    String shipAddressWithoutContactPerson = SalesOrderAction.getAddressAsString(address);

                    if(shipAddressWithoutContactPerson.trim().equals(""))
                    {
                        subform.setShippingAddressId ( quotation.getShippingAddressId () );
                        subform.setShippingAddress ( SalesOrder.getAddressAsString ( customerShippingAddress ) );
                        subform.setContactPersonsForShippingAddress ( quotation.getContactPersonsForShippingAddress () );
                        subform.setShippingContactPerson(quotation.getShippingContactPerson());
                        shippingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getShippingAddressId() , quotation.getShippingAddressAsObject ());
                        shipAddress = CustomerDAO.getAddress ( quotation.getShippingAddressId () );
                        shipAddress.setContactPerson("");
                        shipAddress.setPhoneNumber("");
                        shipAddress.setCellNumber("");
                        shipAddress.setFaxNumber("");
                        shipAddress.setEmail("");
                        shippingAddressMap.put("",SalesOrder.getAddressAsString(shipAddress));
                        quotationFromMap.setShippingAddressMap( shippingAddressMap );
                    }
                    ArrayList defaultShippingAddress = new ArrayList();
                    defaultShippingAddress.add( customerShippingAddress );

                    ArrayList farmatedDefualtShippingAddress = loadShippingAddresses ( defaultShippingAddress );

                    for ( int i = 0; i < farmatedDefualtShippingAddress.size(); i++ ) {
                        org.apache.struts.util.LabelValueBean  bean = ( org.apache.struts.util.LabelValueBean ) farmatedDefualtShippingAddress.get( i );
                        shippingAddresses.add( bean );
                    }

                    subform.setShippingAddresses ( shippingAddresses );
                    quotationFromMap.setShippingAddresses ( shippingAddresses );
                    quotationFromMap.setMfgPartsWithCustomerPartNos( NewSalesOrderDAO.loadManfacturingPartNumbersWithCustomerPartNumbers ( subform.getCustomerId (), subform.getOdmId(), isSample ) );
                    quotationFromMap.setMfgPartsWithLabelNumbers( NewSalesOrderDAO.loadManfacturingPartNumbersWithOdmLabelNumbers ( subform.getCustomerId (), subform.getOdmId(), isSample ) );
                    quotationFromMap.setSalesPersons( NewCustomerDAO.loadAllSalesPersonsforCustomerAndOdm( subform.getCustomerId(), Integer.parseInt( odmId) ) );
                    quotationFromMap.setShippingMethods( CustomerDAO.loadSalesOrderShippingMethods ( subform.getCustomerId() ) );
                    subform.setShippingMethods( CustomerDAO.loadShippingMethodsForCustomerAndOdm ( subform.getCustomerId(), Integer.parseInt(odmId ) ) );
                }
                subform.setIsEndCustomerShipAddress( true );
            }
            quotationFromMap.setContactPersons( subform.getContactPersons () );
            quotationFromMap.setContactPersonsForBillingAddress( subform.getContactPersonsForBillingAddress() );
            quotationFromMap.setContactPersonsForShippingAddress( subform.getContactPersonsForShippingAddress() );
            quotationFromMap.setShippingAddresses( subform.getShippingAddresses() );
            int someValue = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample ).size ();

            if ( someValue == 0 )
            {
                lineItems = getLineItems ( session );
                request.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
            }
            else
            {
                lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample );
                session.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );

                subform.setSalesTaxAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "salesTax" ) ) );
                subform.setSubTotalAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "subTotal" ) ) );
                subform.setOrderTotalAsDouble ( subform.getSubTotalAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSalesTaxAsDouble () );
            }
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );
            request.setAttribute ( "Account", subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingAccount () );

            request.setAttribute ( "QuotationForm", subform );
            saveToken ( request );
            return ( mapping.findForward ( "Quotation" ) );
        }
        else if ( "loadEndUserDetails".equals ( action ) )
        {
            String endUserId = request.getParameter ( "endUserId" );
            ArrayList lineItems = null;
            if ( ( subform.getShippingAddressId () == -1 ) && ( session.getAttribute ( "newShippingAddressId" ) != null ) )
                subform.setShippingAddressId ( Integer.parseInt ( ( String ) session.getAttribute ( "newShippingAddressId" ) ) );
            if ( endUserId != null )
            {
                if ( "".equals ( endUserId.trim () ) )
                {
                    Quotation quotation = QuotationDAO.getQuotationCustomerDetails ( Integer.toString ( subform.getCustomerId () ) );
                    subform.setContactPersons ( quotation.getContactPersons () );
                    subform.setContactPersonsForBillingAddress ( quotation.getContactPersonsForBillingAddress () );
                    subform.setContactPersonsForShippingAddress ( quotation.getContactPersonsForShippingAddress () );
                    subform.setBillingAddress ( SalesOrder.getAddressAsString ( quotation.getBillingAddressAsObject () ));
                    subform.setShippingAddress ( SalesOrder.getAddressAsString ( quotation.getShippingAddressAsObject () ));

                    HashMap billingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getBillingAddressId() , quotation.getBillingAddressAsObject ());
                    Address address= CustomerDAO.getAddress ( quotation.getBillingAddressId () );
                    address.setContactPerson(subform.getCustomerName());
                    address.setCellNumber("");
                    billingAddressMap.put("",SalesOrder.getAddressAsString(address));
                    session.setAttribute ( "billingAddressMap", billingAddressMap  );
                    HashMap shippingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getShippingAddressId() , quotation.getShippingAddressAsObject ());
                    Address shipAddress = CustomerDAO.getAddress ( quotation.getShippingAddressId () );
                    shipAddress.setContactPerson("");
                    shipAddress.setPhoneNumber("");
                    shipAddress.setCellNumber("");
                    shipAddress.setFaxNumber("");
                    shipAddress.setEmail("");
                    shippingAddressMap.put("",SalesOrder.getAddressAsString(shipAddress));
                    session.setAttribute ( "shippingAddressMap", shippingAddressMap );
                    subform.setShippingAddresses ( quotation.getShippingAddresses () );
                    subform.setEndUser ( "" );
                    subform.setBillingAddressId ( quotation.getBillingAddressId () );
                    subform.setShippingAddressId ( quotation.getShippingAddressId () );
                    subform.setBillingContactPerson ( quotation.getBillingContactPerson () );
                    subform.setShippingContactPerson ( quotation.getShippingContactPerson () );
                    session.setAttribute ( "mfgPartsWithCustomerPartNos", NewSalesOrderDAO.loadManfacturingPartNumbersWithCustomerPartNumbers( subform.getCustomerId (), subform.getOdmId(), isSample ) );
                    session.setAttribute ( "mfgPartsWithLabelNumbers", NewSalesOrderDAO.loadManfacturingPartNumbersWithOdmLabelNumbers ( subform.getCustomerId (), subform.getOdmId(), isSample ) );
                }
                else
                {
                    EndUser endUser = EndUserDAO.getEndUserDetails ( Integer.parseInt ( endUserId ) );
                    subform.setContactPersonsForBillingAddress(CustomerDAO.getAllContactPersonsForAddress( endUser.getDefaultBillingAddressId() ));
                    subform.setContactPersonsForShippingAddress(CustomerDAO.getAllContactPersonsForAddress( endUser.getDefaultShippingAddressId() ));
                    subform.setEndUser ( endUser.getEndUserName () );
                    ArrayList shippingAddresses = endUser.getShippingLocations ();
                    shippingAddresses.add ( 0, endUser.getShippingAddress () );
                    subform.setOdmId( -1 );
                    subform.setOdm("");
                    subform.setBillingAddressId ( endUser.getDefaultBillingAddressId () );
                    subform.setShippingAddressId ( endUser.getDefaultShippingAddressId () );
                    subform.setBillingAddress ( SalesOrder.getAddressAsString ( endUser.getBillingAddress () ) );
                    subform.setShippingAddress ( SalesOrder.getAddressAsString ( endUser.getShippingAddress () ) );
                    Quotation quotation = QuotationDAO.getQuotationCustomerDetails ( Integer.toString ( subform.getCustomerId () ) );

                    subform.setBillingContactPerson(endUser.getBillingContactPersonObject().getContactPerson());
                    subform.setShippingContactPerson(endUser.getShippingContactPersonObject().getContactPerson());
                    subform.setContactPersons ( quotation.getContactPersons () );
                    HashMap billingAddressMap = CustomerDAO.getAddressDetailsMap (  subform.getBillingAddressId() , endUser.getBillingAddress ());
                    Address customerAddressObject = CustomerDAO.getAddress ( quotation.getBillingAddressId () );

                    Address billAddress = CustomerDAO.getAddress ( endUser.getDefaultBillingAddressId () );
                    String billContactPersonName = billAddress.getContactPerson();
                    billAddress.setContactPerson(subform.getCustomerName());
                    billAddress.setPhoneNumber(customerAddressObject.getPhoneNumber());
                    billAddress.setCellNumber("");
                    billAddress.setFaxNumber(customerAddressObject.getFaxNumber());
                    billAddress.setEmail(customerAddressObject.getEmail());
                    billingAddressMap.put("",SalesOrder.getAddressAsString(billAddress));
                    session.setAttribute ( "billingAddressMap", billingAddressMap  );
                    if( billContactPersonName == null || billContactPersonName.trim().length() == 0  || billContactPersonName.equals(subform.getCustomerName() ) )
                    {
                        subform.setBillingAddress(SalesOrder.getAddressAsString(billAddress));
                    }
                    HashMap shippingAddressMap = CustomerDAO.getAddressDetailsMap ( subform.getShippingAddressId() , endUser.getShippingAddress ());
                    Address shipAddress = CustomerDAO.getAddress(endUser.getDefaultShippingAddressId());
                    shipAddress.setContactPerson("");
                    shipAddress.setPhoneNumber("");
                    shipAddress.setCellNumber("");
                    shipAddress.setFaxNumber("");
                    shipAddress.setEmail("");
                    shippingAddressMap.put("",SalesOrder.getAddressAsString(shipAddress));
                    session.setAttribute ( "shippingAddressMap", shippingAddressMap  );
                    Address address = endUser.getBillingAddress();
                    String billAddressWithoutContactPerson = SalesOrderAction.getAddressAsString(address);
                    address = endUser.getShippingAddress();
                    String shipAddressWithoutContactPerson = SalesOrderAction.getAddressAsString(address);

                    if ( billAddressWithoutContactPerson.trim ().equals ( "" ) )
                    {
                        subform.setBillingAddressId ( quotation.getBillingAddressId () );
                        Address billingAddress = quotation.getBillingAddressAsObject ();
                        subform.setBillingAddress ( SalesOrder.getAddressAsString ( billingAddress ) );
                        subform.setContactPersonsForBillingAddress ( quotation.getContactPersonsForBillingAddress () );
                        subform.setBillingContactPerson ( quotation.getBillingContactPerson () );
                        billingAddress = CustomerDAO.getAddress ( quotation.getBillingAddressId () );
                        billingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getBillingAddressId() , quotation.getBillingAddressAsObject () );
                        billingAddress.setContactPerson(subform.getCustomerName());
                        billingAddressMap.put("",SalesOrder.getAddressAsString(billingAddress));
                        session.setAttribute ( "billingAddressMap", billingAddressMap  );
                    }
                    if(shipAddressWithoutContactPerson.trim().equals(""))
                    {
                        subform.setShippingAddressId ( quotation.getShippingAddressId () );
                        Address shippingAddress = quotation.getShippingAddressAsObject();
                        subform.setShippingAddress ( SalesOrder.getAddressAsString ( shippingAddress ) );
                        subform.setShippingAddressId( quotation.getShippingAddressId() );
                        //shippingAddresses.add( shippingAddress );
                        subform.setContactPersonsForShippingAddress ( quotation.getContactPersonsForShippingAddress () );
                        subform.setShippingContactPerson(quotation.getShippingContactPerson());
                        shippingAddressMap = CustomerDAO.getAddressDetailsMap ( quotation.getShippingAddressId() , quotation.getShippingAddressAsObject ());
                        shipAddress = CustomerDAO.getAddress ( quotation.getShippingAddressId () );
                        shipAddress.setContactPerson("");
                        shipAddress.setPhoneNumber("");
                        shipAddress.setCellNumber("");
                        shipAddress.setFaxNumber("");
                        shipAddress.setEmail("");
                        shippingAddressMap.put("",SalesOrder.getAddressAsString(shipAddress));
                        session.setAttribute ( "shippingAddressMap", shippingAddressMap );
                        subform.setShippingAddresses ( quotation.getShippingAddresses () );
                    }
                    //Added by sujan on 17th dec 2004 as to get the customer default shipping address when the end user is selected for the quotation.
                    shippingAddresses.add ( CustomerDAO.getAddress ( SalesOrderDAO.getDefaultShippingAddressId( subform.getCustomerId() ) ) );
                    //end adding by sujan.
                    subform.setShippingAddresses ( loadShippingAddresses ( shippingAddresses ) );
                    session.setAttribute ( "mfgPartsWithCustomerPartNos", EndUserDAO.loadManfacturingPartNumbersWithEndUserPartNos ( Integer.parseInt ( endUserId ) ) );
                    session.setAttribute ( "mfgPartsWithLabelNumbers", EndUserDAO.loadManfacturingPartNumbersWithEndUserLabelNumbers( Integer.parseInt ( endUserId ) ) );
                }
                subform.setIsEndCustomerShipAddress( false ); // Added by Veeru on 21st Dec 2004
            }
            session.setAttribute ( "contactPersons", subform.getContactPersons () );
            session.setAttribute ( "billingAddressContactPersons", subform.getContactPersonsForBillingAddress() );
            session.setAttribute ( "shippingAddressContactPersons", subform.getContactPersonsForShippingAddress() );

            /*lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample );
            request.setAttribute ( "lineItems", lineItems );

            request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
            session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );


            subform.setSalesTaxAsDouble(Double.parseDouble((String)request.getAttribute("salesTax")) );
            subform.setSubTotalAsDouble(Double.parseDouble((String)request.getAttribute("subTotal")) );
            subform.setOrderTotalAsDouble(subform.getSubTotalAsDouble()+subform.getFrieghtAsDouble()+subform.getMiscAsDouble()+subform.getSalesTaxAsDouble());*/
            int someValue = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample ).size ();

            if ( someValue == 0 )
            {
                lineItems = getLineItems ( session );
                request.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "mfgPartsWithComments", SalesOrderDAO.loadAllManfacturingPartNumbersWithComments ( subform.getCustomerId (), isSample ) );

            }
            else
            {
                lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample );

                /*if ( "".equals ( endUserId ) )
                {
                    SalesOrderDAO.loadCustomerPartNumbersForLineItems ( null, lineItems, subform.getCustomerId (), subform.getOdmId() );
                }
                else
                {
                    SalesOrderDAO.loadEndUserPartNumbersForLineItems ( null, lineItems, Integer.parseInt ( endUserId ) );
                }*/

                session.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );

                subform.setSalesTaxAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "salesTax" ) ) );
                subform.setSubTotalAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "subTotal" ) ) );
                subform.setOrderTotalAsDouble ( subform.getSubTotalAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSalesTaxAsDouble () );
            }


            //session.setAttribute ( "shippingMethods", session.getAttribute ( "shippingMethods" ) );
            session.setAttribute ( "shippingMethods", CustomerDAO.loadSalesOrderShippingMethods ( subform.getCustomerId() )  );
            session.setAttribute ( "shippingAddresses", subform.getShippingAddresses () );
            //session.setAttribute ("salesPersons",CustomerDAO.loadAllSalesPersonsforCustomer( subform.getCustomerId () ) ) ;
            //session.setAttribute ( "mktgParts", SalesOrderDAO.loadAllMarketingPartNumbers () );
            session.setAttribute ( "salesTaxes", SalesDAO.loadSalesTaxList () );
            session.setAttribute ( "mfgParts", SalesOrderDAO.loadAllManfacturingPartNosOfCustomerWithOutobsolete ( subform.getCustomerId (), isSample ) );
            request.setAttribute ( "Account", subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingAccount () );
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );

            request.setAttribute ( "QuotationForm", subform );
            saveToken ( request );
            return ( mapping.findForward ( "Quotation" ) );
        }
        else if ( "loadShippingAddress".equals ( action ) )
        {
            if ( ( subform.getShippingAddressId () == -1 ) && ( session.getAttribute ( "newShippingAddressId" ) != null ) ) {
                subform.setShippingAddressId ( Integer.parseInt ( ( String ) session.getAttribute ( "newShippingAddressId" ) ) );
                Address address = CustomerDAO.getAddress( subform.getShippingAddressId() );
                loadShippingAddress( address, quotationFromMap.getShippingAddresses(), quotationFromMap );
            }

            int shippingAddressId = subform.getShippingAddressId();
            int defaultShippingAddressId = SalesOrderDAO.getDefaultShippingAddressId( subform.getCustomerId () );

            Address shipAddress = CustomerDAO.getAddressWithContactPersonDetails ( shippingAddressId );
            HashMap shippingAddressMap = new HashMap();
            if(shipAddress != null)
            {
                /*String shipAddressWithoutContactPerson = SalesOrderAction.getAddressAsString( shipAddress );
                if ( "".equals( shipAddressWithoutContactPerson.trim() ) )
                {
                    if ( defaultShippingAddressId != shippingAddressId )
                    {
                        shippingAddressId = defaultShippingAddressId;
                        subform.setShippingAddressId( shippingAddressId);
                        shipAddress = CustomerDAO.getAddressWithContactPersonDetails ( shippingAddressId );
                    }
                }*/
                subform.setShippingContactPerson( shipAddress.getContactPerson() );
                subform.setShippingAddress ( shipAddress.getAddressAsString ());
                shippingAddressMap = CustomerDAO.getAddressDetailsMap ( shippingAddressId, shipAddress);
                shippingAddressMap.put("",shipAddress.getAddressWithoutContactPersonAsString());
            }
            quotationFromMap.setShippingAddressMap( shippingAddressMap );
            quotationFromMap.setContactPersonsForShippingAddress( CustomerDAO.getAllContactPersonsForAddress(  shippingAddressId ) );
            ArrayList lineItems = null;
            int someValue = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample ).size ();
            if ( someValue == 0 )
            {
                lineItems = getLineItems ( session );
                request.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "mfgPartsWithComments", SalesOrderDAO.loadAllManfacturingPartNumbersWithComments ( subform.getCustomerId (), isSample ) );
            }
            else
            {
                lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample );
                session.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );

                subform.setSalesTaxAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "salesTax" ) ) );
                subform.setSubTotalAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "subTotal" ) ) );
                subform.setOrderTotalAsDouble ( subform.getSubTotalAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSalesTaxAsDouble () );
            }
            if ( subform.getOdmId() > 0 )
            {
                quotationFromMap.setSalesPersons( NewCustomerDAO.loadAllSalesPersonsforCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ) ) ;
            }
            else
            {
                quotationFromMap.setSalesPersons( CustomerDAO.loadAllSalesPersonsforCustomer( subform.getCustomerId ())) ;
            }
            quotationFromMap.setShippingMethods( CustomerDAO.loadShippingMethodsForCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ));
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );
            request.setAttribute ( "Account", subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingAccount () );

            request.setAttribute ( "QuotationForm", subform );
            saveToken ( request );
            return ( mapping.findForward ( "Quotation" ) );
        } // End of loadShippingAddress

        else if ( "loadShippingInstructions".equals ( action ) )
        {
            if ( ( subform.getShippingAddressId () == -1 ) && ( session.getAttribute ( "newShippingAddressId" ) != null ) ) {
                subform.setShippingAddressId ( Integer.parseInt ( ( String ) session.getAttribute ( "newShippingAddressId" ) ) );
                Address address = CustomerDAO.getAddress( subform.getShippingAddressId() );
                loadShippingAddress( address, quotationFromMap.getShippingAddresses(), quotationFromMap );
            }
            subform.setShippingInstructions ( NewSalesOrderDAO.loadSelectedShippingInstructions( null, subform.getShippingInstructionsId() ) );

            ArrayList lineItems = null;
            int someValue = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample ).size ();
            if ( someValue == 0 )
            {
                lineItems = getLineItems ( session );
                request.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "mfgPartsWithComments", SalesOrderDAO.loadAllManfacturingPartNumbersWithComments ( subform.getCustomerId (), isSample ) );
            }
            else
            {
                lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample );
                session.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );
                subform.setSalesTaxAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "salesTax" ) ) );
                subform.setSubTotalAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "subTotal" ) ) );
                subform.setOrderTotalAsDouble ( subform.getSubTotalAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSalesTaxAsDouble () );
            }
            if ( subform.getOdmId() > 0 )
            {
                quotationFromMap.setSalesPersons( NewCustomerDAO.loadAllSalesPersonsforCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ) ) ;
            }
            else
            {
                quotationFromMap.setSalesPersons( CustomerDAO.loadAllSalesPersonsforCustomer( subform.getCustomerId ())) ;
            }
            quotationFromMap.setShippingMethods( CustomerDAO.loadShippingMethodsForCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ));
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );
            request.setAttribute ( "Account", subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingAccount () );

            request.setAttribute ( "QuotationForm", subform );
            saveToken ( request );
            return ( mapping.findForward ( "Quotation" ) );
        }

        else if ( "loadEndCustomerDefualtShippingAddress".equals ( action ) )
        {
            ArrayList shippingList = new ArrayList();
            if ( ( subform.getShippingAddressId () == -1 ) && ( session.getAttribute ( "newShippingAddressId" ) != null ) ) {
                subform.setShippingAddressId ( Integer.parseInt ( ( String ) session.getAttribute ( "newShippingAddressId" ) ) );
                Address address = CustomerDAO.getAddress( subform.getShippingAddressId() );
                loadShippingAddress( address, shippingList, quotationFromMap );
            }
            quotationFromMap.setShippingAddresses(shippingList);

            int shippingAddressId = 0 ;

            if ( subform.getIsEndCustomerShipAddress() == false )
            {
                NewSalesOrderDAO.loadCustomerAddressesOfType(shippingList, subform.getCustomerId(), "Shipping");
                shippingAddressId = SalesOrderDAO.getDefaultShippingAddressId( subform.getCustomerId () );
            }
            else
            {
                if ( subform.getOdmId() > 0 )
                {
                    NewSalesOrderDAO.loadCustomerAddressesOfType(shippingList, subform.getOdmId(), "Shipping");
                    shippingAddressId = SalesOrderDAO.getDefaultShippingAddressId( subform.getOdmId () );
                }
                else
                {
                    NewSalesOrderDAO.loadCustomerAddressesOfType(shippingList, subform.getCustomerId(), "Shipping");
                    shippingAddressId = SalesOrderDAO.getDefaultShippingAddressId( subform.getCustomerId () );
                }
            }
            String formContactPerson = null;
            if ( NewSalesOrderDAO.isAddressIdExists( shippingList, subform.getShippingAddressId() ) )
            {
                formContactPerson = subform.getShippingContactPerson();
                shippingAddressId = subform.getShippingAddressId();
            }
            else
            {
                subform.setShippingAddressId(shippingAddressId);
            }

            Address shipAddress = CustomerDAO.getAddress ( shippingAddressId );
            HashMap shippingAddressMap = new HashMap();
            if(shipAddress != null)
            {
                /*String shipAddressWithoutContactPerson = SalesOrderAction.getAddressAsString( shipAddress );
                if ( "".equals( shipAddressWithoutContactPerson.trim() ) )
                {
                    int defaultShippingAddressId = SalesOrderDAO.getDefaultShippingAddressId( subform.getCustomerId () );
                    if ( defaultShippingAddressId != shippingAddressId )
                    {
                        shippingAddressId = defaultShippingAddressId;
                        subform.setShippingAddressId( shippingAddressId);
                        shipAddress = CustomerDAO.getAddress ( shippingAddressId );
                        subform.setShippingContactPerson( shipAddress.getContactPerson() );
                        formContactPerson = null;
                    }
                }*/
                if ( formContactPerson != null )
                {
                    subform.setShippingContactPerson( formContactPerson );
                }
                else
                {
                    subform.setShippingContactPerson( shipAddress.getContactPerson() );
                }
                ContactPerson shippingContactPerson = CustomerDAO.getAddressContactPersonDetails (shippingAddressId , subform.getShippingContactPerson());
                if( shippingContactPerson != null )
                {
                    shipAddress.setContactPerson(shippingContactPerson.getContactPerson());
                    shipAddress.setPhoneNumber(shippingContactPerson.getPhoneNumber());
                    shipAddress.setCellNumber(shippingContactPerson.getCellNumber());
                    shipAddress.setFaxNumber(shippingContactPerson.getFaxNumber());
                    shipAddress.setEmail(shippingContactPerson.getEmail());
                }
                else
                {
                    shipAddress.setContactPerson( "" );
                    shipAddress.setPhoneNumber( "" );
                    shipAddress.setCellNumber( "" );
                    shipAddress.setFaxNumber( "" );
                    shipAddress.setEmail( "" );
                }
                subform.setShippingAddress ( shipAddress.getAddressAsString ());
                shippingAddressMap = CustomerDAO.getAddressDetailsMap ( shippingAddressId, shipAddress);
                shippingAddressMap.put( "",shipAddress.getAddressWithoutContactPersonAsString() );
            }
            quotationFromMap.setShippingAddressMap( shippingAddressMap );
            quotationFromMap.setContactPersonsForShippingAddress( CustomerDAO.getAllContactPersonsForAddress(  shippingAddressId ) );
            ArrayList lineItems = null;
            int someValue = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample ).size ();
            if ( someValue == 0 )
            {
                lineItems = getLineItems ( session );
                request.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "mfgPartsWithComments", SalesOrderDAO.loadAllManfacturingPartNumbersWithComments ( subform.getCustomerId (), isSample ) );
            }
            else
            {
                lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample );
                session.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );


                subform.setSalesTaxAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "salesTax" ) ) );
                subform.setSubTotalAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "subTotal" ) ) );
                subform.setOrderTotalAsDouble ( subform.getSubTotalAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSalesTaxAsDouble () );
            }
            if ( subform.getOdmId() > 0 )
            {
                quotationFromMap.setSalesPersons( NewCustomerDAO.loadAllSalesPersonsforCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ) ) ;
            }
            else
            {
                quotationFromMap.setSalesPersons( CustomerDAO.loadAllSalesPersonsforCustomer( subform.getCustomerId ())) ;
            }
            quotationFromMap.setShippingMethods( CustomerDAO.loadShippingMethodsForCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ));
            quotationFromMap.setMfgPartsWithCustomerPartNos( NewSalesOrderDAO.loadManfacturingPartNumbersWithCustomerPartNumbers( subform.getCustomerId(), subform.getOdmId(), isSample ) ) ;
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );
            request.setAttribute ( "Account", subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingAccount () );
            request.setAttribute ( "QuotationForm", subform );
            saveToken ( request );
            return ( mapping.findForward ( "Quotation" ) );
        } // End of loadEndCustomerDefualtShippingAddress

        else if ( "ConfirmQuotation".equals ( action ) )
        {
            if ( !isTokenValid ( request ) )
            {
                errors.put ( ERROR_QUOTATION_ALREADY_SAVED, null );
            }

            resetToken ( request );

            if ( !errors.isEmpty () )
            {
                request.setAttribute ( SessionKeys.ERROR_MESSAGES, errors );
                saveToken ( request );
                if ( user.getUserType() == Constants.USER_TYPE_CUSTOMER )
                {
                    return ( mapping.findForward ( "modifyQuotation" ) );
                }
                else
                {
                    return ( mapping.findForward ( "successQuotation" ) );

                }
            }

            Quotation quotation = new Quotation ();
            PropertyUtils.copyProperties ( quotation, session.getAttribute ( "QuotationForm" ) );

            String method = "";
            String account = "";
            String temp = quotation.getShippingAccount ();
            account = temp;
            if ( temp != null )
            {
                int index1 = temp.indexOf ( "#" );

                if ( index1 != -1 && index1 != 0 )
                {
                    method = temp.substring ( 0, index1 ).trim ();
                    account = temp.substring ( index1 + 1, temp.length () ).trim ();
                }
            }
            quotation.setShippingAccount ( account );

            String methodName = quotation.getShippingMethodName ();
            int index = methodName.indexOf ( "#" );
            if ( index != -1 && index != 0 )
            {
                quotation.setShippingMethodName ( methodName.substring ( 0, index ).trim () );
            }

            if ( QuotationDAO.isQuotationNoExists ( quotation.getQuotationNo () ) )
            {
                errors.put ( ERROR_QUOTATION_NO_ALREADY_EXISTS, null );
                request.setAttribute ( SessionKeys.ERROR_MESSAGES, errors );

                request.setAttribute ( "QuotationForm", session.getAttribute ( "QuotationForm" ) );

                request.setAttribute ( "lineItems", request.getAttribute ( "lineItems" ) );
                session.setAttribute ( "maxLineItemNo", session.getAttribute ( "maxLineItemNo" ) );
                request.setAttribute ( "Account", subform.getShippingMethod () );
                request.setAttribute ( "Method", subform.getShippingMethodName () );
                saveToken ( request );

                return ( mapping.findForward ( "Quotation" ) );
            }

            DBTransaction dbTransaction = null;
            boolean success = false;
            Alarm alarm = null;
            int quotationId = -1;
            try
            {
                dbTransaction = DBTransaction.getInstance ();
                //System.out.println("dbTransaction = " + dbTransaction);
                dbTransaction.begin ();
                //System.out.println("after begindbTransaction = " + dbTransaction);
                quotation.setIsSample ( ( isSample == 0 ) ? true : false );

                quotation.setEnteredById ( user.getUserId () );
                quotation.setEnteredByName ( user.getFirstName () + " " + user.getLastName () );

                quotationId = QuotationDAO.saveQuotation ( dbTransaction, quotation );

                quotation.setQuotationId ( quotationId );
                quotation.setEnteredDate ( StringUtils.formatDateToString ( new Date ( System.currentTimeMillis () ) ) );
                String contactPerson = quotation.getContactPerson ();
                if ( contactPerson.equals ( quotation.getCustomerName () ) )
                {
                    QuotationDAO.updateAddress ( dbTransaction, quotation.getQuotationId (), quotation.getPhoneNumber (), quotation.getFaxNumber (), quotation.getEmail ());
                }
                else
                {
                    CustomerDAO.updateContactPersonDetails (dbTransaction, quotation.getCustomerId(),quotation.getContactPerson(),
                                                    quotation.getPhoneNumber(),
                                                    quotation.getCellNumber(),
                                                    quotation.getFaxNumber(),
                                                    quotation.getEmail (),
                                                    "");
                }
                if (ConfigManager.isLoadQuotationQuestionnaire())
                {
                    FormFile formFile=( FormFile ) session.getAttribute("questionnairefile"+ quotation.getQuotationNo());
                    session.removeAttribute( "questionnairefile"+ quotation.getQuotationNo());
                    String fileLocation = ConfigManager.getProcessDocFilePath();
                    fileLocation += "/quotationQuestionnaire"+"/" + quotation.getQuotationNo() + "/";
                    File outputDir = new File( fileLocation );
                    // Create the directory if doesnt exist
                        if ( outputDir.exists() == false )
                        {
                            outputDir.mkdirs();
                        }
                    FileUtils.saveFile( formFile.getFileData(), fileLocation + formFile.getFileName());
                    quotation.setContractPriceFileName(fileLocation + formFile.getFileName());
                    QuotationDAO.saveQuotationQuestionnaire ( dbTransaction, quotation );
                      
                }
                QuotationDAO.insertLineItems ( dbTransaction, quotationId, ( ArrayList ) session.getAttribute ( "lineItems" ), user.getUserId (), 0 );

                alarm = QuotationDAO.createAlarm ( dbTransaction, user, quotation, request.getHeader ( "HOST" ) );

                success = true;

                request.setAttribute ( "quotationId", Integer.toString ( quotationId ) );
                request.setAttribute ( "quotationNo", quotation.getQuotationNo () );

            }
            catch ( ScalarException se )
            {
                errors.put ( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_SAVING_QUOTATION_DETAILS );
                errors.put ( ERROR_MESSAGE_CONTACT_SYS_ADMN, null );
                session.setAttribute ( SessionKeys.ERROR_REPORT_SUBJECT, " Error: Could Not Save Quote Details " );
                session.setAttribute ( SessionKeys.ERROR_REPORT, se );
                se.printStackTrace();
            }
            finally
            {
                if ( success == true )
                {
                    dbTransaction.commit ();
                    try {
                        String filesubgroupauto = request.getParameter(attachFileTag.PARAM_FILE_SUB_GROUP_AUTO);
                        if(filesubgroupauto != null && filesubgroupauto.trim().length() > 0) {
                            AttachFileDAO.updateFileSubGroup(null, filesubgroupauto, quotation.getQuotationNo());
                        }
                    } catch (Exception e) {
                        errors.put("Error in attaching files", "Please attach again");
                    }
                    try {
                        String commentsgroupidauto = request.getParameter(InternalCommentsTag.PARAM_COMMENTS_GROUP_ID_AUTO);
                        if(commentsgroupidauto != null && commentsgroupidauto.trim().length() > 0) {
                            InternalCommentsDAO.updateCommentsGroupId(null, commentsgroupidauto, "Quotation-" + quotation.getQuotationNo());
                        }
                    } catch (Exception e) {
                        errors.put("Error in saving Internal Comments", "Please enter again");
                    }
                    try
                    {
                        //alarm.setRecipients ( AlarmDAO.loadRecipientsWithChangeQuoteAccess ( alarm ) );
                        if ( quotation.getSalesPerson() != null && quotation.getSalesPerson().length() > 0 )
                        {
                            SalesPerson salesPerson = NewCustomerDAO.getSalesPersonDetails( null, quotation.getSalesPerson() );
                            if ( salesPerson != null && salesPerson.isQuoteAckMail() )
                            {
                                if ( salesPerson.getAddress() != null && salesPerson.getAddress().getEmail() != null && salesPerson.getAddress().getEmail().trim().length() > 0 )
                                {
                                    alarm.addRecipient ( new AlarmUser( salesPerson.getSalesPerson (), salesPerson.getAddress().getEmail().trim() ) );
                                }
                            }
                        }

                        String quotationStatus = QuotationDAO.getQuotationStatus( quotation.getQuotationNo(), "0", "0", "1", user.getUserId(), "", "0", "", "" );

                        alarm.setSubject( "Quote Notification - Quote Number: " + quotation.getQuotationNo() + " - Customer: " + quotation.getCustomerName() + " - Status: " + quotationStatus );
                        
                        alarm.notifyAllRecipients ( quotation.getHtmlView ( Integer.parseInt ( ( String ) request.getAttribute ( "quotationId" ) ) ) );

                        errors.put ( "Email ", " has been sent to all approvers" );
                    }
                    catch ( Exception e )
                    {
                        errors.put ( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_SENDING_MAILS_TO_APPROVERS );
                        errors.put ( ERROR_MESSAGE_CONTACT_SYS_ADMN, null );
                        session.setAttribute ( SessionKeys.ERROR_REPORT_SUBJECT, " Error: Could Not Send Mail to all Approvers " );
                        session.setAttribute ( SessionKeys.ERROR_REPORT, e );
                    }
                    try
                    {
                        InternalCommentsAction.notifiyInternalComments( "Quotation-" + quotation.getQuotationNo(), null, quotationId, alarm );
                    }
                    catch ( Exception e )
                    {                        
                        errors.put ( ERROR_INTERNAL_SERVER_ERROR, "Could not send Internal Comments notification" );
                    }

                    if ( isSample == 1 )
                    {
                        errors.put ( "Quote = " + quotation.getQuotationNo (), "Saved Successfully" );
                        //errors.put ( "Email ", " has been sent to all approvers" );
                        errors.put ( "View/Print ", "Click here to <a href='javascript:openQuotation();' onmouseover=\"window.status='Click here to View/print Quatation';return true\" onmouseout=\"window.status='';return true\"> view/print </a> Quote Details" );
                    }
                    else
                    {
                        errors.put ( "SampleOrder = " + quotation.getQuotationNo (), "Saved Successfully" );
                        //errors.put ( "Email ", " has been sent to all approvers" );
                        errors.put ( "View/Print ", "Click here to <a href='javascript:openQuotation();' onmouseover=\"window.status='Click here to View/print Quatation';return true\" onmouseout=\"window.status='';return true\" > view/print </a>Sample Order Details" );
                    }
                }
                else
                {
                    dbTransaction.rollback ();

                    if ( isSample == 1 )
                    {
                        errors.put ( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_SAVING_QUOTATION_DETAILS );

                        errors.put ( ERROR_MESSAGE_CONTACT_SYS_ADMN, null );
                        session.setAttribute ( SessionKeys.ERROR_REPORT_SUBJECT, " Error: Could Not Save Quote Details " );
                        session.setAttribute ( SessionKeys.ERROR_REPORT, null );
                    }
                    else
                    {
                        errors.put ( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_SAVING_QUOTATION_DETAILS );
                        errors.put ( ERROR_MESSAGE_CONTACT_SYS_ADMN, null );
                        session.setAttribute ( SessionKeys.ERROR_REPORT_SUBJECT, " Error: Could Not Save Quote Details " );
                        session.setAttribute ( SessionKeys.ERROR_REPORT, null );
                    }
                }
            }

            if ( !errors.isEmpty () )
            {
                request.setAttribute ( SessionKeys.MESSAGES, errors );
            }
            quotationMap.remove( selectedCustomer );
        }
        else if ( "loadFreightInstructions".equals ( action ) )
        {
            if ( ( subform.getShippingAddressId () == -1 ) && ( session.getAttribute ( "newShippingAddressId" ) != null ) ) {
                subform.setShippingAddressId ( Integer.parseInt ( ( String ) session.getAttribute ( "newShippingAddressId" ) ) );
                Address address = CustomerDAO.getAddress( subform.getShippingAddressId() );
                loadShippingAddress( address, quotationFromMap.getShippingAddresses(), quotationFromMap );
            }
            String freightInstructions = null;
            try
            {
                freightInstructions = NewSalesOrderDAO.loadSelectedFreightInstructions( null, subform.getFreightInstructionsId() );
            }
            catch ( ScalarException e )
            {
                System.out.println ( "Exception while loading the FreightInstruction.");
                e.printStackTrace();
            }
            subform.setFreightInstructions ( freightInstructions );

            ArrayList lineItems = null;
            int someValue = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample ).size ();
            if ( someValue == 0 )
            {
                lineItems = getLineItems ( session );
                request.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
            }
            else
            {
                lineItems = loadLineItems ( request, subform.getCustomerId (), errors, info, false, isSample );
                session.setAttribute ( "lineItems", lineItems );
                request.setAttribute ( "lineItemsWithSubtotals", SalesOrderAction.loadLineItemsWithSubTotals ( lineItems ) );
                session.setAttribute ( "maxLineItemNo", request.getAttribute ( "maxLineItemNo" ) );

                subform.setSalesTaxAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "salesTax" ) ) );
                subform.setSubTotalAsDouble ( Double.parseDouble ( ( String ) request.getAttribute ( "subTotal" ) ) );
                subform.setOrderTotalAsDouble ( subform.getSubTotalAsDouble () + subform.getFrieghtAsDouble () + subform.getMiscAsDouble () + subform.getSalesTaxAsDouble () );
            }
            if ( subform.getOdmId() > 0 )
            {
                quotationFromMap.setSalesPersons( NewCustomerDAO.loadAllSalesPersonsforCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ) ) ;
            }
            else
            {
                quotationFromMap.setSalesPersons( CustomerDAO.loadAllSalesPersonsforCustomer( subform.getCustomerId ())) ;
            }
            quotationFromMap.setShippingMethods( CustomerDAO.loadShippingMethodsForCustomerAndOdm( subform.getCustomerId(), subform.getOdmId() ));
            request.setAttribute ( "quoteTypes", QuotationDAO.getQuoteTypeLabelValueList( null ) );
            request.setAttribute ( "applications", QuotationDAO.getQuoteApplicationLabelValueList( null ) );
            request.setAttribute ( "screenDisplayFiledsList", QuotationDAO.getScreenDisplayFiledsList( null ) );
            request.setAttribute ( "Account", subform.getShippingAccount () );
            request.setAttribute ( "Method", subform.getShippingAccount () );

            request.setAttribute ( "QuotationForm", subform );
            saveToken ( request );
            return ( mapping.findForward ( "Quotation" ) );
        } // end loading freightInstructions
        if ( user.getUserType() == Constants.USER_TYPE_CUSTOMER )
        {
            return ( mapping.findForward ( "modifyQuotation" ) );
        }
        else
        {
            return ( mapping.findForward ( "successQuotation" ) );
        }
    }


    public static ArrayList loadLineItems ( HttpServletRequest request, int customerId,
                                            HashMap errors, HashMap info, boolean checkLimits, int isSample ) throws ScalarException
    {
        HttpSession session = request.getSession ();
        String action = request.getParameter ( "action" );
        String[] lineItem = request.getParameterValues ( "lineItemNo" );
        String[] poLineItem = request.getParameterValues ( "poLineItemNo" );
        String[] manufacturingPartNo = request.getParameterValues ( "manufacturingPartNo" );
        String[] quantity = request.getParameterValues ( "quantity" );
        String[] minOrderQty = request.getParameterValues ( "minOrderQty" );
        String[] leadTime = request.getParameterValues ( "leadTime" );
        String[] oldQty = request.getParameterValues ( "oldQty" );
        String[] requestDate = request.getParameterValues ( "requestDate" );
        String[] unitPrice = request.getParameterValues ( "unitPriceAsDouble" );
        String[] reqPrice = request.getParameterValues ( "reqPrice" );
        String[] custResalePrice = request.getParameterValues ( "custResalePrice" );
        String[] suggResalePrice = request.getParameterValues ( "suggResalePrice" );
        String[] quotedDate = null;
        String[] quotedQty = null;
        String[] lineItemDescription = request.getParameterValues ( "lineItemDescription" );
        String[] customerPartNo = request.getParameterValues ( "customerPartNo" );
        String[] newCustPartNo = request.getParameterValues ( "newCustomerPartNo" );
        String[] labelNumber = null;
        String salesTaxType = request.getParameter ( "salesTaxType" );

        if ( ( salesTaxType.equalsIgnoreCase ( "-1" ) ) == true )
        {
            salesTaxType = request.getParameter ( "newSalesState" );
        }
        float taxvalue = SalesOrderDAO.getTaxValue ( null, salesTaxType );
        Float ff = new Float ( taxvalue );
        double tax = ff.doubleValue ();
        ArrayList lineItemsList = new ArrayList ();
        LineItem lineItemInfo = null;

        String zeroPrice = "";
        String productPrice = "";

        int totalQty = 0;
        float subTotal = 0.0f;
        double salesTax = 0.0;
        double finalSubTotal = 0.0;
        int tempLineItemNo = 0;
        boolean found = false;
        for ( int i = 0; i < manufacturingPartNo.length; i++ )
        {
            if ( lineItem[i].trim ().equals ( "" ) )
                lineItem[i] = "0";
            if ( ( manufacturingPartNo[i] != null ) && ( !manufacturingPartNo[i].equals ( "" ) ) )
            {
                if ( quantity[i].equals ( "" ) )
                    quantity[i] = "0";
                if ( unitPrice[i].equals ( "" ) )
                    unitPrice[i] = "0.0";
                lineItemInfo = SalesOrderDAO.loadLineItemInfo ( customerId, Integer.parseInt ( lineItem[i] ),
                                                                null,
                                                                manufacturingPartNo[i],
                                                                requestDate[i], leadTime[i],
                                                                Integer.parseInt ( quantity[i] ),
                                                                StringUtils.formatToFloat ( unitPrice[i] ), isSample);
                if ( lineItemInfo == null )
                {
                    errors.put ( "LineItem No " + lineItem[i], "is not having valid partnumbers, please enter valid partnumbers" );

                }
                //If the lineItem is not valid then it is null, then put all the values entered back to object
                //and sbow the error message to correct it
                if ( lineItemInfo == null )
                {
                    lineItemInfo = new LineItem ();
                    lineItemInfo.setLineItemNo ( Integer.parseInt ( lineItem[i] ) );
                    lineItemInfo.setManufacturingPartNo ( manufacturingPartNo[i] );
                    lineItemInfo.setLineItemDescription ( lineItemDescription[i].trim () );
                    lineItemInfo.setCustomerPartNo ( customerPartNo[i] );
                    if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() ) )
                    {
                        lineItemInfo.setLabelNumber( labelNumber[i] );
                    }
                    lineItemInfo.setQuantity ( Integer.parseInt ( quantity[i] ) );
                    lineItemInfo.setLeadTime (leadTime[i]);

                    lineItemInfo.setUnitPrice ( StringUtils.formatToFloat ( unitPrice[i] ) );
                    lineItemInfo.setUnitPriceAsDouble ( Double.parseDouble ( unitPrice[i] ) );
                    lineItemInfo.setRequestDate ( requestDate[i] );
                }
                else
                {
                    //Need to have the request date before you submit...request date is required field
                    if ( requestDate[i].trim ().length () == 0 )
                        errors.put ( "LineItem No " + lineItem[i], "Please enter Request  Dock Date." );
                }

                if (minOrderQty != null && minOrderQty.length > i) {
                    try {
                        lineItemInfo.setMinOrderQty(Integer.parseInt(minOrderQty[i]));
                    } catch (NumberFormatException ignore) {
                    }
                }

                //If it is not sample need to set unit price and amount
                lineItemInfo.setPoLineItemNo ( Integer.parseInt ( poLineItem[i] ) ); // Added by Basha (08/18/2003)
                zeroPrice = request.getParameter ( "zeroPrice" + lineItem[i] );
                lineItemInfo.setZeroPrice ( ( zeroPrice != null ) ? true : false ); // Modified by Basha (09/22/2003)
                //  to set value to oldQty when it zero for the first time
                if ( "0".equals ( oldQty[i] ) )
                {
                    oldQty[i] = quantity[i];
                }
                //Added Argument requestedDate by Veeru on 8th August 2004
                productPrice = SalesOrderDAO.loadOldQtyPrice ( null, lineItemInfo.getProductId (), customerId, Integer.parseInt ( oldQty[i] ),lineItemInfo.getRequestDate(), isSample);

                if ( ( ( StringUtils.formatToFloat ( unitPrice[i] ) != 0.0 ) || zeroPrice != null ) && ( isSample == 1 ) )
                {
                    if ( ( quantity[i].equalsIgnoreCase ( oldQty[i] ) ) || ( !unitPrice[i].equalsIgnoreCase ( productPrice ) ) )
                    {
                        lineItemInfo.setUnitPrice ( StringUtils.formatToFloat ( Double.toString ( Double.parseDouble ( unitPrice[i] ) ) ) );
                        lineItemInfo.setUnitPriceAsDouble ( Double.parseDouble ( unitPrice[i] ) );
                        double unit_price = Double.parseDouble ( unitPrice[i] );
                        double amt = ( Integer.parseInt ( quantity[i] ) ) * unit_price;
                        lineItemInfo.setAmountAsDouble ( amt );
                    }
                }
                if ( isSample == 0 )
                {
                    lineItemInfo.setUnitPrice ( 0 );
                    lineItemInfo.setUnitPriceAsDouble( 0 );
                    lineItemInfo.setAmount ( 0 );
                }
                lineItemInfo.setIsExpedite ( ( request.getParameter ( "expediteFee" + lineItem[i] ) != null ) ? true : false );

                if ( request.getParameter ( "isTaxable" + lineItem[i] ) != null )
                {
                    lineItemInfo.setIsTaxable ( true );
                    salesTax = salesTax + ( lineItemInfo.getAmountAsDouble () * ( tax / 100 ) );

                }
                if ( ( lineItemDescription[i] == null ) || ( lineItemDescription[i].trim ().length () == 0 ) )
                {
                    String lItemDesc = null;
                    try
                    {
                        lItemDesc = SalesOrderDAO.getLineItemDescriptionByMfgPartNumber ( manufacturingPartNo[i] );
                        lItemDesc = ( ( lItemDesc == null ) ? "" : lItemDesc );
                        lineItemInfo.setLineItemDescription ( lItemDesc );
                    }
                    catch ( ScalarException se )
                    {
                        errors.put ( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_SAVING_SALES_ORDER_DETAILS );
                        errors.put ( ERROR_MESSAGE_CONTACT_SYS_ADMN, null );
                        session.setAttribute ( SessionKeys.ERROR_REPORT_SUBJECT, " Error: Could Not Save Sales Order Details " );
                        session.setAttribute ( SessionKeys.ERROR_REPORT, se );
                    }

                }
                else
                {
                    lineItemInfo.setLineItemDescription ( lineItemDescription[i] );
                }

                lineItemInfo.setCustomerPartNo ( customerPartNo[i] );
                lineItemInfo.setNewCustomerPartNo ( newCustPartNo[i] );
                if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() ) )
                {
                    lineItemInfo.setLabelNumber( labelNumber[i] );
                }

                //calculate total quantity and amount and set it in request

                totalQty = totalQty + lineItemInfo.getQuantity ();
                if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){
                    if( quotedQty[i] != null && quotedQty[i].trim().length() > 0){
                        lineItemInfo.setQuotedQuantity( Integer.parseInt( quotedQty[i] ) );
                    }
                    lineItemInfo.setQuotedDate( quotedDate[i] );
                }
                if ( reqPrice != null && reqPrice.length > i )
                {
                    try
                    {
                        lineItemInfo.setReqPrice( Double.parseDouble ( reqPrice[i] ) );
                    }catch ( NumberFormatException ignore ) {}
                }
                if ( custResalePrice != null && custResalePrice.length > i )
                {
                    try
                    {
                        lineItemInfo.setCustResalePrice( Double.parseDouble ( custResalePrice[i] ) );
                    }catch ( NumberFormatException ignore ) {}
                }
                if ( suggResalePrice != null && suggResalePrice.length > i )
                {
                    try
                    {
                        lineItemInfo.setSuggResalePrice( Double.parseDouble ( suggResalePrice[i] ) );
                    }catch ( NumberFormatException ignore ) {}
                }
                finalSubTotal = finalSubTotal + lineItemInfo.getAmountAsDouble ();
                try
                {
                    lineItemInfo.setAmount ( Float.parseFloat ( StringUtils.formatAmountWithNoOfDecimals ( lineItemInfo.getAmount () ) ) );
                }
                catch ( NumberFormatException ignore ) {}
                request.setAttribute ( "totalQty", Integer.toString ( totalQty ) );
                request.setAttribute ( "salesTax", Double.toString ( salesTax ) );
                request.setAttribute ( "subTotal", Double.toString ( finalSubTotal ) );
                if(Integer.parseInt(lineItem[i]) > tempLineItemNo )
                {
                    tempLineItemNo = Integer.parseInt(lineItem[i]);
                }

                lineItemsList.add ( lineItemInfo );

            }
            else {
                found = true;
            }
        }
        request.setAttribute ( "maxLineItemNo", Integer.toString ( tempLineItemNo + 1 ) );

        request.setAttribute ( "Errors", errors );
        request.setAttribute ( "Info", info );
        // Added on 27th Oct 2004 to reset the Line Item no and PO Line Item no when mfg part number is null.
        if ( found == true )
        {
            LineItem tempLineItem = null;
            int i = 0;
            for ( i = 0; i < lineItemsList.size(); i++ ) {
                tempLineItem = ( LineItem ) lineItemsList.get( i );
                tempLineItem.setLineItemNo ( i + 1 );
                tempLineItem.setPoLineItemNo ( i + 1 );
            }
            request.setAttribute ( "maxLineItemNo", Integer.toString ( i + 1 ) );
        }

        return lineItemsList;
    }
    private void addNewSalesTaxState ( HttpServletRequest request, HttpSession session, HashMap errors, QuotationForm subform )
    {
        String state1 = null;
        String value1 = null;
        String[] newSalesState = new String[1];
        String[] newSalesTax = new String[1];
        boolean checkstate = false;

        try
        {
            state1 = request.getParameter ( "newSalesState" );
            value1 = request.getParameter ( "newSalesTax" );
            String salesTaxType = request.getParameter ( "salesTaxType" );

            if ( "-1".equals ( salesTaxType ) )
            {

                checkstate = SalesOrderDAO.doesSalesTaxStateExist ( null, state1 );

                if ( checkstate == false )
                {

                    if ( ( state1 != null && state1.length () > 0 ) && ( value1 != null && value1.length () > 0 ) )
                    {
                        newSalesState[0] = state1;
                        newSalesTax[0] = value1;

                        SalesDAO.saveSalesTaxes ( newSalesState, newSalesTax, " " );
                        ArrayList salesStatesList = ( ArrayList ) session.getAttribute ( "salesTaxes" );

                        salesStatesList.add ( new org.apache.struts.util.LabelValueBean ( state1 + " - " + value1, state1 ) );
                        session.setAttribute ( "salesTaxes", salesStatesList );
                        subform.setSalesTaxType ( state1 );

                        value1 = null;
                    }
                }
                else
                {
                    errors.put ( "The State '" + state1 + "' already exists", null );
                    request.setAttribute ( "otherstateadded", "false" );
                    request.setAttribute ( "newsalesstate", state1 );
                    request.setAttribute ( "newsalesvalue", value1 );
                }
            }

        }
        catch ( Exception e )
        {
            errors.put ( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_SAVING_NEW_SALES_TAX_STATE );
            errors.put ( ERROR_MESSAGE_CONTACT_SYS_ADMN, null );
            session.setAttribute ( SessionKeys.ERROR_REPORT_SUBJECT, " Error: Could Not Save New Sales Tax State" );
            session.setAttribute ( SessionKeys.ERROR_REPORT, e );
        }
        request.setAttribute ( "Errors", errors );

    }

    public static ArrayList getLineItems ( HttpSession session )
    {
        ArrayList lineItems = new ArrayList ();
        for ( int i = 1; i < 6; i++ )
        {
            LineItem lineItem = new LineItem ();
            lineItem.setLineItemNo ( i );
            lineItem.setPoLineItemNo ( i );
            lineItems.add ( lineItem );
        }
        session.setAttribute ( "maxLineItemNo", "6" );

        return lineItems;
    }

    private void addNewShippingMethod ( HttpServletRequest request, HttpSession session, HashMap errors, HashMap info, QuotationForm subform, Quotation quotationFromMap )
    {
        String customerId = request.getParameter ( "customerId" );
        String method = null;
        String account = null;
        boolean checkmethodexist = true;
        int customerIdvalue = -1;

        if ( customerId != null )
        {
            session.setAttribute ( "addShippingMethodCustomerId", customerId );
        }
        else
        {
            customerId = ( String ) session.getAttribute ( "addShippingMethodCustomerId" );
        }

        String shippingMethod = subform.getShippingMethod ();
        if ( "-2".equalsIgnoreCase ( shippingMethod ) == true )
        {
            try
            {
                method = request.getParameter ( "newshippingMethod" );
                account = request.getParameter ( "newshippingAccount" );
                customerIdvalue = Integer.parseInt ( customerId );
                checkmethodexist = CustomerDAO.doesShippingMethodExist ( null, customerIdvalue, method, account );

                if ( checkmethodexist == false )
                {
                    if ( !( ( method.equals ( "" ) ) && ( account.equals ( "" ) ) ) )
                    {
                        try
                        {
                            CustomerDAO.insertShippingMethod ( null, customerIdvalue, method, account );
                            //ArrayList shippingMethodList = ( ArrayList ) session.getAttribute ( "shippingMethods" );
                            ArrayList shippingMethodList = quotationFromMap.getShippingMethods();

                            //shippingMethodList.add ( new org.apache.struts.util.LabelValueBean (method, account) );
                            //Modified by Sarada on 1st Feb  2004 to get shiping account along with shipping method
                            shippingMethodList.add ( new org.apache.struts.util.LabelValueBean ( method + "   #   " + account, method + "   #   " + account ) );

                            //session.setAttribute ( "shippingMethods", shippingMethodList );
                            quotationFromMap.setShippingMethods( shippingMethodList );

                            subform.setNewshippingAccount ( "" );
                            subform.setNewshippingMethod ( "" );

                            //This Label is added by Kumaraswamy on Oct 8th, 2004.
                            String newShippingMethodLabel = null;
                            try
                            {
                                newShippingMethodLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.NewShippingMethod" );
                                if ( newShippingMethodLabel == null )
                                {
                                    newShippingMethodLabel = Labels.DEFAULT_NEW_SHIPPING_METHOD_LABEL;
                                }
                            }
                            catch ( NullPointerException e )
                            {
                                 newShippingMethodLabel = Labels.DEFAULT_NEW_SHIPPING_METHOD_LABEL;
                            }
                            info.put ( newShippingMethodLabel+" has been stored in database successfully", null );
                        }

                        catch ( ScalarException se )
                        {
                            //This Label is added by Kumaraswamy on Oct 15th, 2004.
                            String shippingMethodLabel = null;
                            try
                            {
                                shippingMethodLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.ShippingMethod" );
                                if ( shippingMethodLabel == null )
                                {
                                    shippingMethodLabel = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
                                }
                            }
                            catch ( NullPointerException e )
                            {
                                shippingMethodLabel    = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
                            }
                            errors.put ( ERROR_INTERNAL_SERVER_ERROR, "Could not Save "+shippingMethodLabel+" Value."+ method );
                            //errors.put ( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_SAVING_SHIPPED_ORDER + method );
                            se.printStackTrace ();
                        }

                    }
                }
                else
                {
                    //These Labels are added by Kumaraswamy on Oct 15th, 2004.
                    String shippingMethodLabel = null;
                    try
                    {
                        shippingMethodLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.ShippingMethod" );
                        if ( shippingMethodLabel == null )
                        {
                            shippingMethodLabel = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
                        }
                    }
                    catch ( NullPointerException e )
                    {
                        shippingMethodLabel    = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
                    }
                    errors.put ( method +" "+ shippingMethodLabel+" already Exists ,Please enter another "+shippingMethodLabel+".", null );
                    //errors.put ( method + " " + ERROR_SHIPPING_METHOD_EXISTS, null );
                }

                subform.setShippingMethodName ( method + "   #   " + account );
                subform.setShippingAccount ( method + "   #   " + account );
                subform.setShippingMethod ( method + "   #   " + account );
                quotationFromMap.setShippingMethod( subform.getShippingMethod() );
            }
            catch ( Exception e )
            {
                e.printStackTrace ();
            }
        }
    }
    // Added by veeru on 19th May 2004
    private ArrayList loadShippingAddresses ( ArrayList shippingAddresses )
    {
        Address address = null;
        ArrayList shippingList = new ArrayList ();
        for ( int i = 0; i < shippingAddresses.size (); i++ )
        {
            address = ( Address ) shippingAddresses.get ( i );

            int shippingAddressId = address.getAddressId ();

            String addrStr = "";
            /* Commented by Prabhanjan (1 Jun 2004). No need to show contact person in shipping address list box as separate list box is available for shipping contact persons.
            if ( ( address.getContactPerson () != null ) && ( address.getContactPerson ().trim ().length () != 0 ) )
            {
                //addrStr = address.getContactPerson();
                shippingList.add ( new org.apache.struts.util.LabelValueBean (
                        address.getContactPerson (), Integer.toString ( address.getAddressId () ) ) );
            }
            */
            if ( ( address.getAddress1 () != null ) && ( address.getAddress1 ().trim ().length () != 0 ) )
            {
                shippingList.add ( new org.apache.struts.util.LabelValueBean (
                        address.getAddress1 (), Integer.toString ( address.getAddressId () ) ) );
            }
            if ( ( address.getAddress2 () != null ) && ( address.getAddress2 ().trim ().length () != 0 ) )
            {
                shippingList.add ( new org.apache.struts.util.LabelValueBean (
                        address.getAddress2 (), Integer.toString ( address.getAddressId () ) ) );
            }
            if ( ( address.getAddress3 () != null ) && ( address.getAddress3 ().trim ().length () != 0 ) )
            {
                shippingList.add ( new org.apache.struts.util.LabelValueBean (
                        address.getAddress3 (), Integer.toString ( address.getAddressId () ) ) );
            }
            if ( ( address.getAddress4 () != null ) && ( address.getAddress4 ().trim ().length () != 0 ) )
            {
                shippingList.add ( new org.apache.struts.util.LabelValueBean (
                        address.getAddress4 (), Integer.toString ( address.getAddressId () ) ) );
            }
            if ( ( address.getCity () != null ) && ( address.getCity ().trim ().length () != 0 ) )
            {
                shippingList.add ( new org.apache.struts.util.LabelValueBean (
                        address.getCity (), Integer.toString ( address.getAddressId () ) ) );
            }

            if ( ( address.getState () != null ) && ( address.getState ().trim ().length () != 0 ) )
            {
                addrStr = addrStr + address.getState ();
            }
            if ( ( address.getZipCode () != null ) && ( address.getZipCode ().trim ().length () != 0 ) )
            {
                if ( ( address.getState () != null ) && ( address.getState ().trim ().length () != 0 ) )
                {
                    addrStr = addrStr + "-";
                }

                addrStr = addrStr + address.getZipCode ();
            }
            if ( ( address.getCountry () != null ) && ( address.getCountry ().trim ().length () != 0 ) )
            {
                if ( ( ( address.getZipCode () != null ) && ( address.getZipCode ().trim ().length () != 0 ) ) || ( ( address.getState () != null ) && ( address.getState ().trim ().length () != 0 ) ) )
                {
                    addrStr = addrStr + ",";
                }
                addrStr = addrStr + address.getCountry ();
            }
            if ( !( "".equals ( addrStr ) ) )
            {
                shippingList.add ( new org.apache.struts.util.LabelValueBean ( addrStr, Integer.toString ( address.getAddressId () ) ) );
            }
            shippingList.add ( new org.apache.struts.util.LabelValueBean ( "", Integer.toString ( address.getAddressId () ) ) );
        }

        //Set all the shippingAddresses in the salesOrder
        return shippingList;
    }
    // Added by veeru on 21st May 2004
    public static void addNewShippingTerms ( HttpServletRequest request, HttpSession session, HashMap errors, HashMap info, QuotationForm subform )
    {
        String shippingTerms = null;
        String newShippingTerms = null;
        boolean checkmethodexist = true;
        shippingTerms = subform.getShippingTerms ();
        if ( "-2".equalsIgnoreCase ( shippingTerms ) == true )
        {
            try
            {
                newShippingTerms = request.getParameter ( "newShippingTerms" );
                if ( newShippingTerms != null )
                {
                    newShippingTerms = newShippingTerms.trim ();
                }
                else
                {
                    newShippingTerms = "";
                }
                if ( newShippingTerms != null && newShippingTerms.trim ().length () != 0 )
                {
                    checkmethodexist = SalesDAO.doesShippingTermsExist ( null, newShippingTerms );
                    if ( checkmethodexist == false )
                    {
                        try
                        {
                            SalesDAO.insertShippingTerms ( null, newShippingTerms );
                            ArrayList shippingTermsList = ( ArrayList ) session.getAttribute ( "allShippingTerms" );
                            shippingTermsList.add ( newShippingTerms );
                            session.setAttribute ( "allShippingTerms", shippingTermsList );
                            info.put ( "New Pay Terms are added successfully", null );
                            subform.setShippingTerms ( newShippingTerms );
                        }
                        catch ( ScalarException se )
                        {
                            //This Label is added by Kumaraswamy on Oct 15th, 2004.
                            String shippingMethodLabel = null;
                            try
                            {
                                shippingMethodLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.ShippingMethod" );
                                if ( shippingMethodLabel == null )
                                {
                                    shippingMethodLabel = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
                                }
                            }
                            catch ( NullPointerException e )
                            {
                                shippingMethodLabel    = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
                            }
                            errors.put ( ERROR_INTERNAL_SERVER_ERROR, "Could not Save "+shippingMethodLabel+" Value."+ newShippingTerms );
                            //errors.put ( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_SAVING_SHIPPED_ORDER + newShippingTerms );
                            se.printStackTrace ();
                        }

                    }//if
                    else
                    {
                        errors.put ( newShippingTerms + " " + ERROR_SHIPPING_TERMS_EXISTS, null );
                    }
                }
            }//try
            catch ( Exception e )
            {
                e.printStackTrace ();
            }
        }
    }
    public static void addNewDeliveryTerms ( HttpServletRequest request, HttpSession session, HashMap errors, HashMap info, QuotationForm subform )
    {
        String deliveryTerms = null;
        String newDeliveryTerms = null;
        boolean checkTermsexist = false;

        deliveryTerms = subform.getDeliveryTerms ();
        if ( "-2".equalsIgnoreCase ( deliveryTerms ) == true )
        {
            try
            {
                newDeliveryTerms = request.getParameter ( "newDeliveryTerms" );
                if ( newDeliveryTerms != null )
                {
                    newDeliveryTerms = newDeliveryTerms.trim ();
                }
                else
                {
                    newDeliveryTerms = "";
                }
                if ( newDeliveryTerms != null && newDeliveryTerms.trim ().length () != 0 )
                {
                    String deliveryTermsLabel = null;
                    try
                    {
                        deliveryTermsLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.DeliveryTerms" );
                        if ( deliveryTermsLabel == null )
                        {
                            deliveryTermsLabel = Labels.DEFAULT_DELIVERY_TERMS_LABEL;
                        }
                    }
                    catch ( NullPointerException e )
                    {
                        deliveryTermsLabel    = Labels.DEFAULT_DELIVERY_TERMS_LABEL;
                    }
                    ArrayList deliveryTermsList = ( ArrayList ) session.getAttribute ( "allDeliveryTerms" );
                    for (int i = 0; i < deliveryTermsList.size(); i++) {
                        if ( newDeliveryTerms.equalsIgnoreCase( ( String )deliveryTermsList.get(i) ) ){
                            checkTermsexist = true;
                            break;
                        }
                    }

                    if ( !checkTermsexist )
                    {
                        try
                        {
                            SalesDAO.insertDeliveryTerms ( null, newDeliveryTerms );

                            deliveryTermsList.add ( newDeliveryTerms );
                            session.setAttribute ( "allDeliveryTerms", deliveryTermsList );
                            info.put ( deliveryTermsLabel+ " added successfully", null );
                            subform.setDeliveryTerms ( newDeliveryTerms );
                        }
                        catch ( ScalarException se )
                        {

                            errors.put ( ERROR_INTERNAL_SERVER_ERROR, "Could not Save "+deliveryTermsLabel+" Value."+ newDeliveryTerms );
                            se.printStackTrace ();
                        }

                    }//if
                    else
                    {
                        errors.put ( newDeliveryTerms + " " + deliveryTermsLabel +" already Exists, Please enter another "+deliveryTermsLabel, null );
                    }
                }
            }//try
            catch ( Exception e )
            {
                e.printStackTrace ();
            }
        }
    }
    public static void addNewShippingInstructions( HttpServletRequest request, HttpSession session, HashMap errors, HashMap info, QuotationForm subform )
    {
        int shippingInstructionsId  = subform.getShippingInstructionsId();
        String shippingInstructions = subform.getShippingInstructions();
        boolean checkInstructionsexist = false;
        if ( shippingInstructionsId == -2  && shippingInstructions != null && shippingInstructions.trim().length() > 0 )
        {
            ArrayList shippingInstructionsList = ( ArrayList )session.getAttribute("shippingInstructions");
            for (int i = 0; i < shippingInstructionsList.size(); i++) {
                org.apache.struts.util.LabelValueBean labelValueBean = (org.apache.struts.util.LabelValueBean) shippingInstructionsList.get(i);
                if ( ( shippingInstructions.trim()).equalsIgnoreCase( labelValueBean.getLabel().trim() ) ) {
                    checkInstructionsexist = true;
                    break;
                }
            }
            if ( !checkInstructionsexist )
            {
                try {
                    shippingInstructionsId = NewSalesOrderDAO.saveShippingInstructions( null, shippingInstructions );
                    subform.setShippingInstructionsId( shippingInstructionsId );
                    shippingInstructionsList.add( new org.apache.struts.util.LabelValueBean( shippingInstructions, shippingInstructionsId+"" ) );
                    info.put ( "New Shipping Instructions added successfully", null );
                } catch( Exception e){
                    errors.put("Shipping Instructions ","Could not save Shipping Instructions" );
                }
            } else {
                    errors.put("Shipping Instructions already exists, Please enter another Shipping Instructions ", null );
            }
        }
    }

    public static void loadEndUserContactPersonDetails ( SalesOrder salesOrder, int endUserId ) throws ScalarException
    {
        salesOrder.setContactPersons ( EndUserDAO.getAllContactPersonsForEndUser ( endUserId ) );

        String contactPersonName = salesOrder.getContactPerson ();
        // If condition added by Prabhanjan (16 Apr 2004)
        if ( !( contactPersonName.equals ( salesOrder.getCustomerName () ) ) )
        {
            if ( contactPersonName != null && contactPersonName.trim ().length () != 0 )
            {
                ContactPerson contactPerson = EndUserDAO.getEndUserContactPersonDetails ( endUserId, salesOrder.getContactPerson () );
                if ( contactPerson != null )
                {
                    salesOrder.setContactPerson ( contactPerson.getContactPerson () );
                    salesOrder.setPhoneNumber ( contactPerson.getPhoneNumber () );
                    salesOrder.setCellNumber ( contactPerson.getCellNumber () );
                    salesOrder.setFaxNumber ( contactPerson.getFaxNumber () );
                    salesOrder.setEmail ( contactPerson.getEmail () );
                    salesOrder.setAddress ( contactPerson.getAddress () );
                }
                else if ( contactPerson == null )
                {
                    salesOrder.setContactPerson ( "" );
                    salesOrder.setPhoneNumber ( "" );
                    salesOrder.setCellNumber ( "" );
                    salesOrder.setFaxNumber ( "" );
                    salesOrder.setEmail ( "" );
                    salesOrder.setAddress ( "" );
                }
            }
            else if ( contactPersonName == null || contactPersonName.trim ().length () == 0 )
            {
                Address addressObject = CustomerDAO.getAddress ( salesOrder.getBillingAddressId () );
                //Added by Sarada on 16th March2004
                salesOrder.setContactPerson ( salesOrder.getCustomerName () );
                salesOrder.setEmail ( addressObject.getEmail () );
                salesOrder.setPhoneNumber ( addressObject.getPhoneNumber () );
                salesOrder.setFaxNumber ( addressObject.getFaxNumber () );
                salesOrder.setCellNumber ( "" );
                salesOrder.setAddress ( "" );
            }
        }
    }
    public static void addNewFreightInstructions( HttpServletRequest request, HttpSession session, HashMap errors, HashMap info, QuotationForm subform )
    {
        int freightInstructionsId  = subform.getFreightInstructionsId();
        String freightInstructions = ( subform.getFreightInstructions() == null ? "" : subform.getFreightInstructions().trim() );

        if ( freightInstructionsId == -2 && !"".equals ( freightInstructions ) )
        {
            try
            {
                ArrayList freightInstructionsList = ( ArrayList )session.getAttribute ( "freightInstructions" );
                int freightInstructionsSize = ( freightInstructionsList == null ? 0 : freightInstructionsList.size() );
                org.apache.struts.util.LabelValueBean freightInstructionsBean = null;
                for ( int i=0; i < freightInstructionsSize; i++ )
                {
                    freightInstructionsBean = ( org.apache.struts.util.LabelValueBean )freightInstructionsList.get( i );
                    if ( freightInstructionsBean != null && freightInstructions.equalsIgnoreCase( freightInstructionsBean.getLabel() ) )
                    {
                        try
                        {
                            freightInstructionsId = Integer.parseInt ( freightInstructionsBean.getValue() );
                        }
                        catch ( NumberFormatException e )
                        {
                            freightInstructionsId = 0;
                        }
                        break;
                    }
                }
                if ( freightInstructionsId <= 0 )
                {
                    freightInstructionsId = NewSalesOrderDAO.saveFreightInstructions( null, freightInstructions );
                    //ArrayList freightInstructionsList = (ArrayList)session.getAttribute("freightInstructions");
                    if ( freightInstructionsList == null )
                    {
                        freightInstructionsList = new ArrayList();
                    }
                    freightInstructions = freightInstructions.length() < 29 ? freightInstructions : freightInstructions.substring(0,25)+"...";
                    int idx = 0;
                    if ( freightInstructionsSize > 0 )
                    {
                          idx = freightInstructionsSize - 1 ;
                    }
                    freightInstructionsList.add( idx, new org.apache.struts.util.LabelValueBean( freightInstructions, freightInstructionsId+"" ) );
                }
                subform.setFreightInstructionsId(freightInstructionsId);
                info.put ( "New Freight Instructions added successfully", null );
            }
            catch( Exception e)
            {
                errors.put("Freight Instructions ","Could not save Freight Instructions" );
            }

        }
    }

    public static void loadShippingAddress( Address address, ArrayList shippingList, Quotation quotationFromMap )
    {
            String addrStr = "";
           if ( ( address.getAddress1 () != null ) && ( address.getAddress1 ().trim ().length () != 0 ) )
           {
               shippingList.add ( new org.apache.struts.util.LabelValueBean (
                       address.getAddress1 (), Integer.toString ( address.getAddressId () ) ) );
           }
           if ( ( address.getAddress2 () != null ) && ( address.getAddress2 ().trim ().length () != 0 ) )
           {
               shippingList.add ( new org.apache.struts.util.LabelValueBean (
                       address.getAddress2 (), Integer.toString ( address.getAddressId () ) ) );
           }
           if ( ( address.getAddress3 () != null ) && ( address.getAddress3 ().trim ().length () != 0 ) )
           {
               shippingList.add ( new org.apache.struts.util.LabelValueBean (
                       address.getAddress3 (), Integer.toString ( address.getAddressId () ) ) );
           }
           if ( ( address.getAddress4 () != null ) && ( address.getAddress4 ().trim ().length () != 0 ) )
           {
               shippingList.add ( new org.apache.struts.util.LabelValueBean (
                       address.getAddress4 (), Integer.toString ( address.getAddressId () ) ) );
           }
           if ( ( address.getCity () != null ) && ( address.getCity ().trim ().length () != 0 ) )
           {
               shippingList.add ( new org.apache.struts.util.LabelValueBean (
                       address.getCity (), Integer.toString ( address.getAddressId () ) ) );
           }

           if ( ( address.getState () != null ) && ( address.getState ().trim ().length () != 0 ) )
           {
               addrStr = addrStr + address.getState ();
           }
           if ( ( address.getZipCode () != null ) && ( address.getZipCode ().trim ().length () != 0 ) )
           {
               if ( ( address.getState () != null ) && ( address.getState ().trim ().length () != 0 ) )
               {
                   addrStr = addrStr + "-";
               }
               addrStr = addrStr + address.getZipCode ();
           }
           if ( ( address.getCountry () != null ) && ( address.getCountry ().trim ().length () != 0 ) )
           {
               if ( ( ( address.getZipCode () != null ) && ( address.getZipCode ().trim ().length () != 0 ) ) || ( ( address.getState () != null ) && ( address.getState ().trim ().length () != 0 ) ) )
               {
                   addrStr = addrStr + ",";
               }
               addrStr = addrStr + address.getCountry ();
           }
           if ( !( "".equals ( addrStr ) ) )
           {
               shippingList.add ( new org.apache.struts.util.LabelValueBean ( addrStr, Integer.toString ( address.getAddressId () ) ) );
           }
           shippingList.add ( new org.apache.struts.util.LabelValueBean ( "", Integer.toString ( address.getAddressId () ) ) );
           ArrayList shippingContactPersons = new ArrayList();
           shippingContactPersons.add( address.getContactPerson() );
           quotationFromMap.setContactPersonsForShippingAddress( shippingContactPersons );
       }
    public static ArrayList  getQuotationTypesList()
    {
        ArrayList quotationTypesList = new ArrayList();
        quotationTypesList.add (new org.apache.struts.util.LabelValueBean ("Price base on quantity", "Price base on quantity"));
        quotationTypesList.add (new org.apache.struts.util.LabelValueBean ("One price, any quantity", "One price, any quantity"));
        quotationTypesList.add (new org.apache.struts.util.LabelValueBean ("Price out in time", "Price out in time"));
        return quotationTypesList;
    }
    public static ArrayList  getQtyPerOptionsList()
    {
        ArrayList qtyPerOptionsList = new ArrayList();
        qtyPerOptionsList.add (new org.apache.struts.util.LabelValueBean("Year", "Year"));
        qtyPerOptionsList.add (new org.apache.struts.util.LabelValueBean("Quarter", "Quarter"));
        qtyPerOptionsList.add (new org.apache.struts.util.LabelValueBean("Month" , "Month"));
        qtyPerOptionsList.add (new org.apache.struts.util.LabelValueBean("Order", "Order"));
        qtyPerOptionsList.add (new org.apache.struts.util.LabelValueBean("Once", "Once"));
        qtyPerOptionsList.add (new org.apache.struts.util.LabelValueBean("N/A", "NA"));
        return qtyPerOptionsList;
    }

     public  static ArrayList  getCommitmentsList()
        {
            ArrayList commitmentsList = new ArrayList();
            commitmentsList.add (new org.apache.struts.util.LabelValueBean("Exceeded", "Exceeded" ));
            commitmentsList.add (new org.apache.struts.util.LabelValueBean("Met", "Met" ));
            commitmentsList.add (new org.apache.struts.util.LabelValueBean("Below expected", "Below expected"));
            commitmentsList.add (new org.apache.struts.util.LabelValueBean("N/A", "NA" ));
            return commitmentsList;
        }

     public  static ArrayList  getQuantityiesList()
        {
            ArrayList quantityiesList = new ArrayList();
            quantityiesList.add (new org.apache.struts.util.LabelValueBean("Maintained flat", "Maintained flat" ));
            quantityiesList.add (new org.apache.struts.util.LabelValueBean("Moderately aggressive reduction in", "Moderately aggressive reduction in"));
            quantityiesList.add (new org.apache.struts.util.LabelValueBean("Extremely aggressive reduction in", "Extremely aggressive reduction in" ));
            quantityiesList.add (new org.apache.struts.util.LabelValueBean("N/A",	"NA" ));
            return quantityiesList;
        }

    public static ArrayList getPriceDiscountOptionsList()
    {
        ArrayList priceDiscountOptionsList = new ArrayList();
        priceDiscountOptionsList.add (new org.apache.struts.util.LabelValueBean("Competition" , "Competition"  ));
        priceDiscountOptionsList.add (new org.apache.struts.util.LabelValueBean("Strategic customer" , "Strategic customer"));
        priceDiscountOptionsList.add (new org.apache.struts.util.LabelValueBean("Contract negotiation" , "Contract negotiation"));
        priceDiscountOptionsList.add (new org.apache.struts.util.LabelValueBean("Increased volumes" ,  "Increased volumes"));
        priceDiscountOptionsList.add (new org.apache.struts.util.LabelValueBean("New design opportunity" , "New design opportunity"));
        priceDiscountOptionsList.add (new org.apache.struts.util.LabelValueBean("Doing us a favor", "Doing us a favor" ));
        priceDiscountOptionsList.add (new org.apache.struts.util.LabelValueBean("Price promotion", "Price promotion" ));
        priceDiscountOptionsList.add (new org.apache.struts.util.LabelValueBean("N/A" , "NA" ));
        return priceDiscountOptionsList;
    }
    public static ArrayList getRebateGoalsList()
    {
        ArrayList rebatGoalsList = new ArrayList();
        rebatGoalsList.add (new org.apache.struts.util.LabelValueBean("Units", "Units"));
        rebatGoalsList.add (new org.apache.struts.util.LabelValueBean("Dollar", "Dollar"));
        rebatGoalsList.add (new org.apache.struts.util.LabelValueBean("Other", "Other"));
        return rebatGoalsList;
    }
    public static ArrayList getCompetitorsList()
    {
        ArrayList competitorsList = new ArrayList();
        competitorsList.add (new org.apache.struts.util.LabelValueBean("Other", "Other"));
        competitorsList.add (new org.apache.struts.util.LabelValueBean("N/A", "NA"));
        return competitorsList;
    }
}
